if thread has no error handling, try main thread handler before panicking

This commit is contained in:
Roberto Ierusalimschy 2009-03-03 15:51:24 -03:00
parent facfcd497f
commit 910310d3ba
1 changed files with 13 additions and 7 deletions

10
ldo.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldo.c,v 2.51 2008/11/06 12:43:51 roberto Exp roberto $ ** $Id: ldo.c,v 2.52 2009/02/18 14:52:03 roberto Exp roberto $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -83,8 +83,13 @@ void luaD_throw (lua_State *L, int errcode) {
L->errorJmp->status = errcode; L->errorJmp->status = errcode;
LUAI_THROW(L, L->errorJmp); LUAI_THROW(L, L->errorJmp);
} }
else { /* thread has no error handler */
L->status = cast_byte(errcode); /* mark it as dead */
if (G(L)->mainthread->errorJmp) { /* main thread has a handler? */
setobjs2s(L, G(L)->mainthread->top++, L->top - 1); /* copy error obj. */
luaD_throw(G(L)->mainthread, errcode); /* jump to it */
}
else { else {
L->status = cast_byte(errcode);
if (G(L)->panic) { if (G(L)->panic) {
lua_unlock(L); lua_unlock(L);
G(L)->panic(L); G(L)->panic(L);
@ -92,6 +97,7 @@ void luaD_throw (lua_State *L, int errcode) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
}
int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {