lua-users home
lua-l archive

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


> That's indeed what I used it for. It allows multiple concurrent Lua
> scripts to run inside a single thread:

> void opcodecounthook(lua_State *L, lua_Debug *ar) {
>    /* We can't yield across a metamethod/C-call boundary. */
>    if (L->nCcalls > 0) return;
>    /* Yield without args */
>    lua_yield(L, 0);
>    /* never reached */

lua_yield doesn't do a throw, so that "never reached" isn't quite
true. After it returns to Lua, Lua returns to the caller, saving
its state so that it can resume.

The multiple concurrency would also be put at risk if the Lua
script included something like:

table.foreach(table_with_a_million_keys, some_long_computation)

But it otherwise seems quite reasonable.

> Yielding from the line count hook should be useful for stepping through
> a Lua program with a synchronous update of some source code display
> on the C side.

I thought about that but the limitations on yielding hooks seem too
extreme for a debugger. Anyway, you could just do the synchronous
update without the yield, though, couldn't you?

The example of the "A" language seems interesting, although the
limitations are also extreme: in addition to coroutines and
pcalls, a lot of other language features become forbidden
(such as table.foreach, as above). (But what would this restrictive
"A" language be, I wonder? Have you actually tried this code?)