[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Forcing coroutine.resume to call the yielding function again
- From: Andreas Falkenhahn <andreas@...>
- Date: Tue, 20 Aug 2019 13:23:57 +0200
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 <firstname.lastname@example.org> 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.
Andreas Falkenhahn mailto:email@example.com