The coroutine library provides a set of functions for working with co-routines, including coroutine.create, coroutine.resume, coroutine.yield, and coroutine.status, among others. These functions allow you to create and manipulate co-routines in Lua. Co-routines provide a way to write cooperative multitasking code in Lua. They allow you to pause the execution of one function and switch to another function, without losing the state of the first function. This can be useful for writing programs that need to perform multiple tasks simultaneously or for implementing state machines.
coroutine coroutine.create(function f)¶
ReturnsA coroutine.Function that creates a new coroutine with the given function f. The coroutine is initially in a suspended state and can be resumed using coroutine.resume.
function coroutine.wrap(function f)¶
ReturnsA function.Function that creates a new coroutine from the given function f, and returns a new function that, when called, resumes the coroutine and returns its values.
table coroutine.resume(coroutine co, ... arguments)¶
ReturnsValues yielded or returned.Function that resumes the given coroutine co, passing any additional arguments to the coroutine function.
ReturnsThe running coroutine.Function that returns the running coroutine.
string coroutine.status(coroutine co)¶
ReturnsThe status string.Function that returns the status of the given coroutine co. The possible values returned by coroutine.status are "running", "suspended", "normal", "dead", or "error".
table coroutine.yield(... arguments)¶
ReturnsValues resumed.Function that yields the current coroutine, returning any additional values passed as arguments. When the coroutine is resumed again, it will resume execution from the point where the coroutine.yield call was made.