diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-10-24 16:46:12 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-10-24 16:46:12 -0300 |
| commit | be822a5f1c0a0cd3f63790ffe761b6a13a69134f (patch) | |
| tree | 4b768952eac5a4911b06948c8d80495da59b32bc | |
| parent | 9f5a052c27a3182bb29250b99fd622cf9ae5f965 (diff) | |
| download | lua-be822a5f1c0a0cd3f63790ffe761b6a13a69134f.tar.gz lua-be822a5f1c0a0cd3f63790ffe761b6a13a69134f.tar.bz2 lua-be822a5f1c0a0cd3f63790ffe761b6a13a69134f.zip | |
xpcall now may get arguments to function to be called
| -rw-r--r-- | lbaselib.c | 13 |
1 files changed, 8 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.193 2006/10/10 17:40:17 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.194 2006/10/20 19:30:53 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 | */ |
| @@ -381,10 +381,13 @@ static int luaB_pcall (lua_State *L) { | |||
| 381 | 381 | ||
| 382 | static int luaB_xpcall (lua_State *L) { | 382 | static int luaB_xpcall (lua_State *L) { |
| 383 | int status; | 383 | int status; |
| 384 | luaL_checkany(L, 2); | 384 | int n = lua_gettop(L); |
| 385 | lua_settop(L, 2); | 385 | luaL_argcheck(L, n >= 2, 2, "value expected"); |
| 386 | lua_insert(L, 1); /* put error function under function to be called */ | 386 | lua_pushvalue(L, 1); /* exchange function... */ |
| 387 | status = lua_pcall(L, 0, LUA_MULTRET, 1); | 387 | lua_pushvalue(L, 2); /* ...and error handler */ |
| 388 | lua_replace(L, 1); | ||
| 389 | lua_replace(L, 2); | ||
| 390 | status = lua_pcall(L, n - 2, LUA_MULTRET, 1); | ||
| 388 | lua_pushboolean(L, (status == LUA_OK)); | 391 | lua_pushboolean(L, (status == LUA_OK)); |
| 389 | lua_replace(L, 1); | 392 | lua_replace(L, 1); |
| 390 | return lua_gettop(L); /* return status + all results */ | 393 | return lua_gettop(L); /* return status + all results */ |
