lua-users home
lua-l archive

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

> - Where is documentation of the coroutine C API?

Nowhere (currently) ;-)

> - Is the above legal usage? In particular, is it allowable to pass the
> same lua state into both parameters of lua_resume?

No. You should create another state ("thread", actually) to be your "base"
thread. You do not need to run any Lua code in that thread, but you need
it to receive any values passed back by yield (or return).

> - Is it possible to achieve the same without a special function in
> the lua script (main() in the above example), that is, break out and
> resume the top level script instead of some function embedded in it?

Yes. In Lua 5.0, you can call luaL_loadbuffer from the auxlib. This
function loads the chunk and leaves its main function (i.e, the top
level script) on the stack. You then call lua_cobegin on it.

> - Is it possible to yield on a regular basis, e.g. every few opcodes,
> without having to pepper the script with yields?

Not now (5.0 alpha). We hope to correct that before the release of 5.0 final.
(You will be able to yield from a "count" hook, a hook that is called
every "count" opcodes.) (5.0 alpha already has count hooks, but you cannot
yield from a hook.)

-- Roberto