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.
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.
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.
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".
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.