diff --git a/lapi.c b/lapi.c index 9edc043f..72f38c93 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 1.182 2002/04/02 20:43:18 roberto Exp roberto $ +** $Id: lapi.c,v 1.183 2002/04/05 18:54:31 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -98,6 +98,15 @@ LUA_API int lua_checkstack (lua_State *L, int size) { } +LUA_API lua_CFunction lua_setpanicf (lua_State *L, lua_CFunction panicf) { + lua_CFunction old; + lua_lock(L); + old = G(L)->panic; + G(L)->panic = panicf; + lua_unlock(L); + return old; +} + /* ** basic stack manipulation diff --git a/ldo.c b/ldo.c index fc0c4122..29276f1b 100644 --- a/ldo.c +++ b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 1.169 2002/04/10 12:10:54 roberto Exp roberto $ +** $Id: ldo.c,v 1.170 2002/04/15 19:34:42 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -501,8 +501,7 @@ void luaD_breakrun (lua_State *L, int errcode) { longjmp(L->errorJmp->b, 1); } else { - if (errcode != LUA_ERRMEM && errcode != LUA_ERRERR) - message(L, "unable to recover; exiting\n"); + G(L)->panic(L); exit(EXIT_FAILURE); } } diff --git a/lstate.c b/lstate.c index 7b7466d6..714fac6a 100644 --- a/lstate.c +++ b/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 1.87 2002/03/11 12:45:00 roberto Exp roberto $ +** $Id: lstate.c,v 1.88 2002/03/20 12:52:32 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -25,6 +25,16 @@ static void close_state (lua_State *L); +/* +** you can change this function through the official API +** call `lua_setpanicf' +*/ +static int default_panic (lua_State *L) { + fprintf(stderr, "unable to recover; exiting\n"); + return 0; +} + + static void stack_init (lua_State *L, lua_State *OL) { L->stack = luaM_newvector(OL, BASIC_STACK_SIZE, TObject); L->stacksize = BASIC_STACK_SIZE; @@ -52,6 +62,7 @@ static void f_luaopen (lua_State *L, void *ud) { G(L)->strt.hash = NULL; G(L)->Mbuffer = NULL; G(L)->Mbuffsize = 0; + G(L)->panic = &default_panic; G(L)->rootproto = NULL; G(L)->rootcl = NULL; G(L)->roottable = NULL; diff --git a/lstate.h b/lstate.h index 3bb3fa5d..6c2cfee9 100644 --- a/lstate.h +++ b/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 1.81 2002/03/26 20:46:10 roberto Exp roberto $ +** $Id: lstate.h,v 1.82 2002/04/10 12:11:07 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -112,6 +112,7 @@ typedef struct global_State { size_t Mbuffsize; /* size of Mbuffer */ lu_mem GCthreshold; lu_mem nblocks; /* number of `bytes' currently allocated */ + lua_CFunction panic; /* to be called in unprotected errors */ TString *tmname[TM_N]; /* array with tag-method names */ } global_State; diff --git a/lua.h b/lua.h index 73e60082..4764e1d1 100644 --- a/lua.h +++ b/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.125 2002/03/27 15:30:41 roberto Exp roberto $ +** $Id: lua.h,v 1.126 2002/04/05 18:54:31 roberto Exp roberto $ ** Lua - An Extensible Extension Language ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil ** e-mail: info@lua.org @@ -100,6 +100,8 @@ LUA_API void lua_close (lua_State *L); LUA_API lua_State *lua_newthread (lua_State *L); LUA_API void lua_closethread (lua_State *L, lua_State *thread); +LUA_API lua_CFunction lua_setpanicf (lua_State *L, lua_CFunction panicf); + /* ** basic stack manipulation