Reference index · Official Lua 5.2 coroutine library · C Lua 5.2.4 source · Implementation
Install with state.OpenCoroutineLibrary().
| API / official reference | Inputs and result | Lua-CSharp implementation notes and differences |
|---|---|---|
coroutine.create(f) |
Creates a suspended coroutine whose body is f; returns a thread. |
A C# LuaFunction can be the body, analogous to using a C function in C Lua. Host functions participate in the managed call machinery. |
coroutine.resume(co [, ...]) |
Starts/resumes co; returns true followed by yielded or final results, or false, error for a script failure. Resume arguments become body arguments or yield results. |
Can await asynchronous C# work. Host cancellation follows the managed execution cancellation protocol rather than becoming an ordinary script failure. |
coroutine.running() |
Returns the current thread and a boolean identifying the main thread. | Threads are represented by LuaState objects. They are not dedicated OS threads. |
coroutine.status(co) |
Reports running, suspended, normal, or dead. |
Awaiting C# work does not itself create a Lua yield/resume exchange. |
coroutine.wrap(f) |
Returns a resume function that forwards results and raises script failures instead of returning a success boolean. | The wrapper is a managed closure capturing the coroutine. Its capture is visible to the supported debug upvalue APIs. |
coroutine.yield(...) |
Suspends the current coroutine and passes values to its resumer. Later resume arguments become the yield's results. | Main-thread yields and yields across non-yieldable library callbacks fail. C# await is separate: an async host callback can await without being allowed to call Lua yield. |
See async and cancellation and the C# coroutine guide. No Lua 5.3/5.4 additions such as coroutine.isyieldable or coroutine.close are installed; this library targets Lua 5.2.