[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Breaking infinite loops / stopping code execution from C
- From: read.beyond.data@...
- From: Celvin <read.beyond.data@...>
- Date: Tue, 20 Aug 2002 18:55:07 -0300
- Date: Tue, 20 Aug 2002 23:56:01 +0200
At 16:28 20.08.2002 -0500, Kelmar wrote:
lua_error() doesn't appear to call exit() to me; however, lua_error()
can be easily replaced using lua_register(). You can define your
own custom error handler this way. This allows you to redirect the
output to say, a window, instaead of stderr.
Thanks Kelmar, but this is not my problem after all. I already replaced
error-msg output to a window in my gui application, but this has never been
the problem ;)
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);
}
}
You'll see that it WILL call exit(EXIT_FAILURE), which is by the way also
in the docs:
"If lua_error is called from a C function that has been called from Lua,
then the corresponding Lua execution terminates, as if an error had
occurred inside Lua code. Otherwise, the whole host program terminates with
a call to exit(EXIT_FAILURE). "
Actually, my problem is, I'm using LUA to develop an application which is
completely driven by user scripts. It's targeted for an audience with
almost no knowledge in programming/scripting, so there definitely will be a
lot of errors. I'm now in dire need for a way to STOP EXECUTION immediately
if the user clicks a button on the gui. This should stop the whole script
and reset LUA back to a fresh state, breaking out from infinite loops etc.,
but neither terminate nor corrupt the application in another way except for
just stopping script execution. lua_error() WILL terminate the whole host
programm, which is not acceptable. Setting up a timer / counter may work
for infinite loops, but there are other situations when the script needs to
be stopped. Imagine the common Ctrl-Break, which is exactly what I'd need....
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....
Thanks, Celvin