From a2fa48a570b01b2a2cd37f01799f08f693fc5892 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 6 Aug 2002 12:32:22 -0300 Subject: new (old?) error handling scheme --- lbaselib.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'lbaselib.c') diff --git a/lbaselib.c b/lbaselib.c index 8ff09683..b05a1b15 100644 --- a/lbaselib.c +++ b/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 */ } -- cgit v1.2.3-55-g6feb