new (old?) error handling scheme
This commit is contained in:
22
lbaselib.c
22
lbaselib.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lbaselib.c,v 1.91 2002/07/17 16:25:13 roberto Exp roberto $
|
||||
** $Id: lbaselib.c,v 1.92 2002/08/05 14:46:02 roberto Exp roberto $
|
||||
** Basic library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -276,9 +276,7 @@ static int luaB_unpack (lua_State *L) {
|
||||
static int luaB_pcall (lua_State *L) {
|
||||
int status;
|
||||
luaL_check_any(L, 1);
|
||||
status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET);
|
||||
if (status) /* error? */
|
||||
lua_pcallreset(L); /* reset error handler */
|
||||
status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0);
|
||||
lua_pushboolean(L, (status == 0));
|
||||
lua_insert(L, 1);
|
||||
return lua_gettop(L); /* return status + all results */
|
||||
@@ -287,22 +285,12 @@ static int luaB_pcall (lua_State *L) {
|
||||
|
||||
static int luaB_xpcall (lua_State *L) {
|
||||
int status;
|
||||
int ref;
|
||||
luaL_check_any(L, 2);
|
||||
lua_settop(L, 2);
|
||||
ref = lua_ref(L, 1); /* save error function */
|
||||
status = lua_pcall(L, 0, LUA_MULTRET);
|
||||
if (status) { /* error? */
|
||||
if (status == LUA_ERRRUN) { /* run-time error? */
|
||||
lua_getref(L, ref); /* get error function */
|
||||
lua_pushvalue(L, -2); /* error message */
|
||||
lua_call(L, 1, 1); /* call error function */
|
||||
}
|
||||
lua_pcallreset(L); /* reset error handler */
|
||||
}
|
||||
lua_unref(L, ref); /* free reference */
|
||||
lua_insert(L, 1); /* put error function under function to be called */
|
||||
status = lua_pcall(L, 0, LUA_MULTRET, 1);
|
||||
lua_pushboolean(L, (status == 0));
|
||||
lua_insert(L, 1);
|
||||
lua_replace(L, 1);
|
||||
return lua_gettop(L); /* return status + all results */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user