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.4 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-2009 Mike Pall. Coco is free software, released under the MIT/X 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.
Please visit the Download page to fetch the current version of Coco.
News
- 2009-09-08 Coco 1.1.6 has been released
- This release fixes compilation of Coco with -fPIC on x64. Also, for faster context switching GCC inline assembler has been added for Sparc platforms.
- 2009-09-08 Coco has moved!
-
Coco has moved to its own domain:
http://coco.luajit.org/
Please update your links and bookmarks — thank you!