lua-users home
lua-l archive

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

You may be interested to know that the Nmap Scripting Engine (NSE)
also does this:

Nice to learn that the problem of nested coroutines appears in
other software too!

It's good to see you generalized it into a library. I'm curious, do
you have an instance where there is more than one level of nesting?

No, currently i only use nested coroutines with two levels: iterators in
redis-lua ( and copas
( in the underlying sockets.
To make them work together, i had to patch both libraries.

The main problem in using the nested coroutines library is that,
usually, Lua scripts use the global `coroutine` variable, instead of
creating a local copy of it. So we can't just replace `_G.coroutine`
with a nestable one before requiring the module.

Search for instance the use of `coroutine` in:

If modules used a local `coroutine` variable, we could at least
monkey-patch libraries as below:

    local coromake = require "coroutine.make"
    _G.coroutine = coromake ()
    local copas = require "copas"
    _G.coroutine = coromake ()
    local redis = require "redis"
    _G.coroutine = coromake ()

The best solution being, of course, to use coronest in those libraries ;-)