lua-users home
lua-l archive

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

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).

The reason I want to do this is because I want scripts to be self-cleaning. They will setup any resources in SETUP, and everything will be cleaned up in CLEANUP independent of whatever happens in between.

Using LUA_VERSION "Lua 5.1 (alpha)".


// David Morris-Oliveros
// Camera & Lua Coder
// Team Bondi

Team Bondi Pty Ltd
Level 2, 608 Harris Street
Ultimo, NSW 2007
Tel: +61 (0)2 8218 1500
Fax: +61 (0)2 8218 1507
This email may contain confidential information.  If you are not
the intended recipient, you may not copy or deliver this message to
anyone. In such case, you should destroy this message and kindly
notify the sender by reply email. Opinions, conclusions and other
information in this message that do not relate to the official business
of our firm shall be understood as neither given nor endorsed by it.