class Lua::Coroutine
- Lua::Coroutine
- Lua::Object
- Reference
- Object
Defined in:
lua/object/coroutine.crConstructors
-
.new(stack, function : Function | Nil = nil)
Creates new Coroutine with it's own stack and a function to execute.
Instance Method Summary
Instance methods inherited from class Lua::Object
ref : Int32?
ref,
release(stack = @stack)
release
Constructor methods inherited from class Lua::Object
new(stack : Stack, ref : Int32 | Nil)
new
Constructor Detail
Creates new Coroutine with it's own stack and a function to execute.
lua = Lua.load
f = lua.run %q{
return function()
print("before yield")
coroutine.yield()
print("after yield")
end
}
co = lua.newthread(f.as Lua::Function)
co.resume # before yield
co.status # => YIELD
co.resume # after yield
co.status # => OK
Stack may return coroutine. In this case we do not need to pass a function 'cause coroutine should already have it:
t = lua.run %q {
function s(x)
return coroutine.yield(x) * 10
end
return coroutine.create(s)
}
co = t.as(Lua::Coroutine)
co.resume # => nil
co.resume(4.2) # => 42.0