diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-04-16 14:08:28 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-04-16 14:08:28 -0300 |
| commit | c11d374c592d10b8ed649ffe501191039ee18757 (patch) | |
| tree | 52a3b434d6197ae36c7f132b370c9807251effe0 | |
| parent | 13230c451ba2feaef1c92c391451ee6471b15bb7 (diff) | |
| download | lua-c11d374c592d10b8ed649ffe501191039ee18757.tar.gz lua-c11d374c592d10b8ed649ffe501191039ee18757.tar.bz2 lua-c11d374c592d10b8ed649ffe501191039ee18757.zip | |
`panic' function configurable via API
| -rw-r--r-- | lapi.c | 11 | ||||
| -rw-r--r-- | ldo.c | 5 | ||||
| -rw-r--r-- | lstate.c | 13 | ||||
| -rw-r--r-- | lstate.h | 3 | ||||
| -rw-r--r-- | lua.h | 4 |
5 files changed, 29 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.182 2002/04/02 20:43:18 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.183 2002/04/05 18:54:31 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -98,6 +98,15 @@ LUA_API int lua_checkstack (lua_State *L, int size) { | |||
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | 100 | ||
| 101 | LUA_API lua_CFunction lua_setpanicf (lua_State *L, lua_CFunction panicf) { | ||
| 102 | lua_CFunction old; | ||
| 103 | lua_lock(L); | ||
| 104 | old = G(L)->panic; | ||
| 105 | G(L)->panic = panicf; | ||
| 106 | lua_unlock(L); | ||
| 107 | return old; | ||
| 108 | } | ||
| 109 | |||
| 101 | 110 | ||
| 102 | /* | 111 | /* |
| 103 | ** basic stack manipulation | 112 | ** basic stack manipulation |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.169 2002/04/10 12:10:54 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.170 2002/04/15 19:34:42 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -501,8 +501,7 @@ void luaD_breakrun (lua_State *L, int errcode) { | |||
| 501 | longjmp(L->errorJmp->b, 1); | 501 | longjmp(L->errorJmp->b, 1); |
| 502 | } | 502 | } |
| 503 | else { | 503 | else { |
| 504 | if (errcode != LUA_ERRMEM && errcode != LUA_ERRERR) | 504 | G(L)->panic(L); |
| 505 | message(L, "unable to recover; exiting\n"); | ||
| 506 | exit(EXIT_FAILURE); | 505 | exit(EXIT_FAILURE); |
| 507 | } | 506 | } |
| 508 | } | 507 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 1.87 2002/03/11 12:45:00 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 1.88 2002/03/20 12:52:32 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -25,6 +25,16 @@ | |||
| 25 | static void close_state (lua_State *L); | 25 | static void close_state (lua_State *L); |
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | /* | ||
| 29 | ** you can change this function through the official API | ||
| 30 | ** call `lua_setpanicf' | ||
| 31 | */ | ||
| 32 | static int default_panic (lua_State *L) { | ||
| 33 | fprintf(stderr, "unable to recover; exiting\n"); | ||
| 34 | return 0; | ||
| 35 | } | ||
| 36 | |||
| 37 | |||
| 28 | static void stack_init (lua_State *L, lua_State *OL) { | 38 | static void stack_init (lua_State *L, lua_State *OL) { |
| 29 | L->stack = luaM_newvector(OL, BASIC_STACK_SIZE, TObject); | 39 | L->stack = luaM_newvector(OL, BASIC_STACK_SIZE, TObject); |
| 30 | L->stacksize = BASIC_STACK_SIZE; | 40 | L->stacksize = BASIC_STACK_SIZE; |
| @@ -52,6 +62,7 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
| 52 | G(L)->strt.hash = NULL; | 62 | G(L)->strt.hash = NULL; |
| 53 | G(L)->Mbuffer = NULL; | 63 | G(L)->Mbuffer = NULL; |
| 54 | G(L)->Mbuffsize = 0; | 64 | G(L)->Mbuffsize = 0; |
| 65 | G(L)->panic = &default_panic; | ||
| 55 | G(L)->rootproto = NULL; | 66 | G(L)->rootproto = NULL; |
| 56 | G(L)->rootcl = NULL; | 67 | G(L)->rootcl = NULL; |
| 57 | G(L)->roottable = NULL; | 68 | G(L)->roottable = NULL; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 1.81 2002/03/26 20:46:10 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.82 2002/04/10 12:11:07 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -112,6 +112,7 @@ typedef struct global_State { | |||
| 112 | size_t Mbuffsize; /* size of Mbuffer */ | 112 | size_t Mbuffsize; /* size of Mbuffer */ |
| 113 | lu_mem GCthreshold; | 113 | lu_mem GCthreshold; |
| 114 | lu_mem nblocks; /* number of `bytes' currently allocated */ | 114 | lu_mem nblocks; /* number of `bytes' currently allocated */ |
| 115 | lua_CFunction panic; /* to be called in unprotected errors */ | ||
| 115 | TString *tmname[TM_N]; /* array with tag-method names */ | 116 | TString *tmname[TM_N]; /* array with tag-method names */ |
| 116 | } global_State; | 117 | } global_State; |
| 117 | 118 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.125 2002/03/27 15:30:41 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.126 2002/04/05 18:54:31 roberto Exp roberto $ |
| 3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
| 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
| 5 | ** e-mail: info@lua.org | 5 | ** e-mail: info@lua.org |
| @@ -100,6 +100,8 @@ LUA_API void lua_close (lua_State *L); | |||
| 100 | LUA_API lua_State *lua_newthread (lua_State *L); | 100 | LUA_API lua_State *lua_newthread (lua_State *L); |
| 101 | LUA_API void lua_closethread (lua_State *L, lua_State *thread); | 101 | LUA_API void lua_closethread (lua_State *L, lua_State *thread); |
| 102 | 102 | ||
| 103 | LUA_API lua_CFunction lua_setpanicf (lua_State *L, lua_CFunction panicf); | ||
| 104 | |||
| 103 | 105 | ||
| 104 | /* | 106 | /* |
| 105 | ** basic stack manipulation | 107 | ** basic stack manipulation |
