lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I am pleased to announce the first stable release of `coronest`, a
module to allow the manipulation of nested coroutines in Lua.

Coroutines are a powerful notion to suspend and resume execution of
lightweight threads. It can be used for instance for scheduling, as in
copas, or for iteration.

When mixing these two uses, a problem arises: there is no way to specify
which coroutine.resume should intercept a coroutine.yield.

This module provides a thin wrapper around the standard coroutine module
to allow the definition of complex behaviors with nested coroutines.


This module is available as a Lua rock:

    luarocks install coronest


Everywhere you are using the standard Lua coroutine module, replace it
with an instance of the nested coroutines:

    local coroutine = require "coroutine.make" ()

For a full example, please look at the example:

Compatibility and Testing

Nested coroutines should be compatible with any version of Lua
supporting coroutines (well, at least from 5.1). As the module is
written in pure Lua, it also works with LuaJIT.

This module comes with tests imported from the Lua testsuite, but using
the coroutine.make instead of standard coroutines; they allow to check
that nested coroutines do not break anything.


This module has been built after this discussion on StackOverflow:
Even if Alban Linard (saucisson) owns the repository, the main
contributor is Philipp Janda (siffiejoe).