lua-users home
lua-l archive

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


Hi,

in my application I use a lua_error call with a unique
private argument to establish 'exit' behaviour
(without actually terminating my app, but only the Lua
environment.)  To be sure that this 'exit' reaches the
outermost stack frame I redefined pcall and xpcall
(that would otherwise catch the 'exit') to rethrow the
'exit' error.  All this can be easily done, but there
is one thing that's nagging me.

The new implementation of xpcall(f, err) uses the
following error handler and rethrows the error if it
is my special 'exit' message (the original 'err'
argument is the first upvalue in the code below):

int check_for_exit(lua_State *L)
{
  if (lua_touserdata(L, 1) != my_exit_error)
  {
    /* call original handler */
    lua_pushvalue(L, lua_upvalueindex(1));
    lua_insert(L, 1);
    lua_call(L, 1, 1);
  }
  return 1;
}

So it calls 'err' for all error messages except my own
'exit' message.  Simple enough, only, the lua_call
above adds a new stack frame that will show up in a
stack traceback...  This is no show stopper but the
additional line in the traceback looks mysterious
enough that I want to avoid it.

For an 'err' handler that is a C function (such as
debug.traceback) I managed to omit the extra frame by
directly calling the handler as a C function (using
lua_tocfunction).  Is there a solution for Lua
functions?  Maybe I'm taking the wrong approach?  Is
there an alternative implementation for a 'soft' exit?

--
Wim



	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/