I have a few coroutines running within a stateful world.
I want to be able to guard against dodgy scripts that aren't written
properly, so I setup a little protocol that all my coroutined scripts
have to follow:
-- begin
function SETUP() ... end
function RUN() ... end
function CLEANUP() ... end
-- end
SETUP & CLEANUP are optional - they'll be called if present. RUN is
compulsory, if not present, an assert will fire, and we'll all run off
to fix that script. The script is executed with lua_resume to populate
_G with these functions, then they are retrieved and called, SETUP &
CLEANUP with lua_pcall and RUN with lua_resume (because I want o
manually timeslice them).
I want my script system to be able to recover from an error within
RUN(). But I have found that if i call error() or lua_error within
RUN(), lua_resume with the correct code (LUA_ERRERR), but I can't
really do anything else with that lua_State, if I try to
lua_pushnumber() it will assert (I have lua asserts turned on).