Trying to recover from an error in a coroutine

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Trying to recover from an error in a coroutine

David Morris-Oliveros
I sent this email last month, and never got a reply, and since it's
something that i don't know how to address, i would like some advice,
thanks in advance.

----------

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

Cheers

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


------------------------------------------------------------------------
Contact:
Team Bondi Pty Ltd
Level 2, 608 Harris Street
Ultimo, NSW 2007
Australia
Tel: +61 (0)2 8218 1500
Fax: +61 (0)2 8218 1507
Web: http://www.teambondi.com
------------------------------------------------------------------------
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.
------------------------------------------------------------------------




------------------------------------------------------------------------
Contact:
Team Bondi Pty Ltd
Level 2, 608 Harris Street
Ultimo, NSW 2007
Australia
Tel: +61 (0)2 8218 1500
Fax: +61 (0)2 8218 1507
Web: http://www.teambondi.com
------------------------------------------------------------------------
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.
------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Trying to recover from an error in a coroutine

Andre Carregal
On Wed, 18 Jan 2006 14:53:27 +1100, David Morris-Oliveros <[hidden email]> wrote:

> I sent this email last month, and never got a reply, and since it's
> something that i don't know how to address, i would like some advice,
> thanks in advance.

By your description of the problem, maybe you should consider some sandboxing solution. You can have a look at VEnv for an example of such sandboxes (or at least for the general usage pattern).

André Carregal