lua-users home
lua-l archive

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


> I've seen that luaD_breakrun() checks wether the errorJmp member of
> lua_State is set or not. Is there any way to set errorJmp to my own
> error recovery routine ?

You can encapsulate your main function ("main"?) into a Cfunction, and
then call it through lua_call. Then, any error inside your code will
be caught by lua_call, that will return an error code to you (the following
code is 4.0 beta, but it is easily adapted to older versions):

int oldmain (lua_State *L) {
  ...
  return 0;
}

void newmain () {
  lua_State *L = lua_newstate(0);
  if (L == NULL) ... /* memory error: cannot open state */
  lua_pushcfunction(L, oldmain);
  if (lua_call(L, 0, 0) != 0) {  /* error: do your own cleaning */
    ...


(Theoretically, you still can get an unhandled memory error during 
`lua_pushcfunction'. But it needs less than 100 bytes to work...) 

-- Roberto