lua-users home
lua-l archive

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


Am Di., 28. März 2023 um 22:58 Uhr schrieb Gé Weijers <ge@weijers.org>:
> The current version, 5.4.x, can yield from C and then continue. I typically don't do that, but when I call Lua from C I use lua_callk so the called Lua routine can yield the coroutine. The downside is that you have to provide an explicit continuation function that's called after a yield and resume because the C stack was obliterated, but it's definitely possible to do that. See section 4.5 of the Lua 5.4 reference manual.


Yes correct, I also use this nicely, if I want to execute a "user Lua
command" from a resumed thread - then this "user Lua command" can
invoke yielding again without problems.

Just you have to be sure, that you invoice this lua_callk inside a
resumed thread... .

You can NOT just invoke this in some "microcontroller main loop" from
the "lua base state" or so... then you run into a Lua error "try to
yield from non-resumed state" or similar... .