lua-users home
lua-l archive

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

There's probably a misunderstanding here: Of course I'm not intending to have the C function continue where it left off. This is obviously impossible. I just want the C function to be called again. The C function code will always be run from its entry point, not from somewhere in between.

On 20.08.2019 at 08:58 Tim Hill wrote:

>> On Aug 19, 2019, at 7:07 AM, Andreas Falkenhahn <> 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

Best regards,
 Andreas Falkenhahn