Coco is a small extension to get True C Coroutine semantics for Lua 5.1. Coco is available as a patch set against the standard Lua 5.1.5 source distribution.
Coco is also integrated into » LuaJIT 1.x to allow yielding for JIT compiled functions. But note that Coco does not depend on LuaJIT and works fine with plain Lua.
Coco is Copyright © 2004-2016 Mike Pall. Coco is free software, released under the » MIT license (same license as the Lua core).
Features
True C coroutine semantics mean you can yield from a coroutine across a C call boundary and resume back to it. Coco allows you to use a dedicated C stack for each coroutine. Resuming a coroutine and yielding from a coroutine automatically switches C stacks. No changes are needed to your Lua source code.
In particular you can now:
- Yield across all metamethods (not advised for __gc).
- Yield across iterator functions (for x in func do).
- Yield across callbacks (table.foreach(), dofile(), ...).
- Yield across protected callbacks (pcall(), xpcall(), ...).
- Yield from C functions and resume back to them.
Coco needs some machine-specific features, but runs fine on Linux, *BSD, Mac OS X, Windows and probably anything else you can find.
More ...
Please click on one of the links in the navigation bar to your left to learn more.
Click on the Logo in the upper left corner to visit the Coco project page on the web. All other links to online resources are marked with a '»'.