I need to create a Lua API function to close/exit a Lua state
from a Lua script.
While “os.exit” will exit the entire host application, I just want to “exit” one (of multiple) Lua states and return to the “lua_pcall” in C, while the application (and the other states) keep running.
Something like this:
Some Lua code
Lua pcall -->
more Lua code
call "state exit" function -------------|
Lua code that should not be executed |
More Lua code that should not be executed |
[continue here] <------------------------------|
It cannot be just a luaL_error call, since this will be caught by a pcall in the Lua code.
Is there some recommended method to do this?
It should work with Lua 5.2, 5.3 and 5.4 and use only C and Lua (no C++, no operating system dependent code or CPU dependent code like asm).
I could try to build some setjmp/longjmp code around it, but
I’m wondering if there might be some built-in feature, e.g., some Lua error/exceptions
that can only be handled in C but not in Lua? In my case, I will call "lua_close" immediately after and I don't need to resume any operation in this state. But for curiosity, is there a way to keep the state "fully operational" after such an operation?