lua-users home
lua-l archive

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



> On Aug 19, 2019, at 7:07 AM, Andreas Falkenhahn <andreas@falkenhahn.com> wrote:
> 
> I think it is possible, you just need the right trick ;) I've now come up with something that seems to do the job: The key to success was realizing that it is perfectly legal for Lua hooks to yield. Since Lua hooks can be called before every instruction I can just use this insight to yield before OP_CALL instead of during it.
> 

No, Philippe is quite correct, there is no “trick” you can pull to work around this. To implement coroutines, Lua uses “long jumps” in C, and these implicitly demolish the C call stack. This means that lua_yield() NEVER RETURNS and any function that calls lua_yield() is abandoned (and any nested outer C functions as well). Whatever you do can not work around the fact that to yield a coroutine MUST demolish the C stack but the very way in which Lua intermixes the Lua and C stacks.

—Tim