lua-users home
lua-l archive

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


----- Original Message -----
From: <read.beyond.data@gmx.net>; "Celvin" <read.beyond.data@gmx.net>
To: "Multiple recipients of list" <lua-l@tecgraf.puc-rio.br>
Sent: Tuesday, August 20, 2002 4:55 PM
Subject: Re: Breaking infinite loops / stopping code execution from C


> At 16:28 20.08.2002 -0500, Kelmar wrote:
>

] ... SNIP ... [

> If you take a look at the lua_error() implementation in the LUA source:
>
> LUA_API void lua_error (lua_State *L, const char *s) {
>    if (s) message(L, s);
>    luaD_breakrun(L, LUA_ERRRUN);
> }
>
> void luaD_breakrun (lua_State *L, int errcode) {
>    if (L->errorJmp) {
>      L->errorJmp->status = errcode;
>      longjmp(L->errorJmp->b, 1);
>    }
>    else {
>      if (errcode != LUA_ERRMEM)
>        message(L, "unable to recover; exiting\n");
>      exit(EXIT_FAILURE);
>    }
> }
>

Hrm, must have confused it with a different part of the source, but you are
correct there.

] ... SNIP ... [

>
> I'm almost desperate as I can't seem to find a way on my own, development
> has stagnated since I stumpled upon this...hope anyone has an idea, I'd
> REALLY appreciate it....
>

If I'm reading that correctly, if the Lua code is executing I would
susspect that L->errorJmp would have a valid jump point becuase the
only way for the script code to actually be executed is if it was
started by a previous C call to the Lua API, thus setting the long
jump pointer back to that point.

I.e. this looks to be more of a sanity check than an actual
realworld check.

This does however raise the problem of possible race conflits if
that is true.  From the sounds of things your executing the Lua
inturpreture in a seprate thread.

I could also see the user hitting Ctrl+Break when the script >isn't<
running, thus causing luaD_breakrun() to call exit() as well.

What I might do in this situation is build a custom Lua library
with a replaced luaD_breakrun() function (no telling what else calls
it) that calls my own version of exit() or PostQuitMessage() or
whatever else you might need.

I might actually have it send a message to the other thread saying,
"hey there was an error, reset the lua_State variable after I'm done"

Kelmar K. Firesun (IRL: Bryce Simonds)