mirror of
https://github.com/lua/lua.git
synced 2025-01-28 06:03:00 +08:00
xpcall now may get arguments to function to be called
This commit is contained in:
parent
9f5a052c27
commit
be822a5f1c
13
lbaselib.c
13
lbaselib.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lbaselib.c,v 1.193 2006/10/10 17:40:17 roberto Exp roberto $
|
** $Id: lbaselib.c,v 1.194 2006/10/20 19:30:53 roberto Exp roberto $
|
||||||
** Basic library
|
** Basic library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -381,10 +381,13 @@ static int luaB_pcall (lua_State *L) {
|
|||||||
|
|
||||||
static int luaB_xpcall (lua_State *L) {
|
static int luaB_xpcall (lua_State *L) {
|
||||||
int status;
|
int status;
|
||||||
luaL_checkany(L, 2);
|
int n = lua_gettop(L);
|
||||||
lua_settop(L, 2);
|
luaL_argcheck(L, n >= 2, 2, "value expected");
|
||||||
lua_insert(L, 1); /* put error function under function to be called */
|
lua_pushvalue(L, 1); /* exchange function... */
|
||||||
status = lua_pcall(L, 0, LUA_MULTRET, 1);
|
lua_pushvalue(L, 2); /* ...and error handler */
|
||||||
|
lua_replace(L, 1);
|
||||||
|
lua_replace(L, 2);
|
||||||
|
status = lua_pcall(L, n - 2, LUA_MULTRET, 1);
|
||||||
lua_pushboolean(L, (status == LUA_OK));
|
lua_pushboolean(L, (status == LUA_OK));
|
||||||
lua_replace(L, 1);
|
lua_replace(L, 1);
|
||||||
return lua_gettop(L); /* return status + all results */
|
return lua_gettop(L); /* return status + all results */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user