Game Development Reference
In-Depth Information
Coroutine Functions
Several functions are associated with working with coroutines. This section provides brief descriptions
of these functions.
coroutine.create ( f )
This function creates a new coroutine with the function body f , which should be a Lua function. On
successful creation, it returns the new coroutine an object with the type thread .
thread = coroutine.create(function() print("Started") end)
coroutine.resume(thread)
co . The first time this function is called,
val1, ... ) are all passed as arguments to the main function.
true plus any values passed to yield or any values returned by the body function.
returns false plus an error message.
coroutine.running ( )
This function returns the running coroutine, or nil when the running coroutine is the main one.
print( coroutine.running(thread))
thread = coroutine.create( function() print("Hello") end)
print( coroutine.running(thread))
coroutine.status ( co )
This function returns the status of the coroutine co as a string. The possible return values are
running : If the coroutine is running
suspended : If the coroutine is suspended in a call to yield or hasn't started
running
normal : If the coroutine is active but not running
dead : If the coroutine has finished its body function or has stopped with an
error
print( coroutine.status(thread))
thread = coroutine.create( function() print("Hello") end)
print( coroutine.status(thread))
 
Search WWH ::




Custom Search