diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-06 12:32:22 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-06 12:32:22 -0300 |
commit | a2fa48a570b01b2a2cd37f01799f08f693fc5892 (patch) | |
tree | b41fc7e88f7f941ae1589921f8d7c0ff57146f4d /lbaselib.c | |
parent | 8b2b8790b5c419282f4fa0c7faa168379647b3b9 (diff) | |
download | lua-a2fa48a570b01b2a2cd37f01799f08f693fc5892.tar.gz lua-a2fa48a570b01b2a2cd37f01799f08f693fc5892.tar.bz2 lua-a2fa48a570b01b2a2cd37f01799f08f693fc5892.zip |
new (old?) error handling scheme
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 22 |
1 files changed, 5 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.91 2002/07/17 16:25:13 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.92 2002/08/05 14:46:02 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -276,9 +276,7 @@ static int luaB_unpack (lua_State *L) { | |||
276 | static int luaB_pcall (lua_State *L) { | 276 | static int luaB_pcall (lua_State *L) { |
277 | int status; | 277 | int status; |
278 | luaL_check_any(L, 1); | 278 | luaL_check_any(L, 1); |
279 | status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET); | 279 | status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0); |
280 | if (status) /* error? */ | ||
281 | lua_pcallreset(L); /* reset error handler */ | ||
282 | lua_pushboolean(L, (status == 0)); | 280 | lua_pushboolean(L, (status == 0)); |
283 | lua_insert(L, 1); | 281 | lua_insert(L, 1); |
284 | return lua_gettop(L); /* return status + all results */ | 282 | return lua_gettop(L); /* return status + all results */ |
@@ -287,22 +285,12 @@ static int luaB_pcall (lua_State *L) { | |||
287 | 285 | ||
288 | static int luaB_xpcall (lua_State *L) { | 286 | static int luaB_xpcall (lua_State *L) { |
289 | int status; | 287 | int status; |
290 | int ref; | ||
291 | luaL_check_any(L, 2); | 288 | luaL_check_any(L, 2); |
292 | lua_settop(L, 2); | 289 | lua_settop(L, 2); |
293 | ref = lua_ref(L, 1); /* save error function */ | 290 | lua_insert(L, 1); /* put error function under function to be called */ |
294 | status = lua_pcall(L, 0, LUA_MULTRET); | 291 | status = lua_pcall(L, 0, LUA_MULTRET, 1); |
295 | if (status) { /* error? */ | ||
296 | if (status == LUA_ERRRUN) { /* run-time error? */ | ||
297 | lua_getref(L, ref); /* get error function */ | ||
298 | lua_pushvalue(L, -2); /* error message */ | ||
299 | lua_call(L, 1, 1); /* call error function */ | ||
300 | } | ||
301 | lua_pcallreset(L); /* reset error handler */ | ||
302 | } | ||
303 | lua_unref(L, ref); /* free reference */ | ||
304 | lua_pushboolean(L, (status == 0)); | 292 | lua_pushboolean(L, (status == 0)); |
305 | lua_insert(L, 1); | 293 | lua_replace(L, 1); |
306 | return lua_gettop(L); /* return status + all results */ | 294 | return lua_gettop(L); /* return status + all results */ |
307 | } | 295 | } |
308 | 296 | ||