mirror of https://github.com/rusefi/lua.git
make treatment of 'pcall' and 'xpcall' more similar
This commit is contained in:
parent
888d39ea75
commit
7133e20c94
25
lbaselib.c
25
lbaselib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lbaselib.c,v 1.266 2011/09/30 12:43:54 roberto Exp roberto $
|
** $Id: lbaselib.c,v 1.267 2011/11/09 19:28:27 roberto Exp roberto $
|
||||||
** Basic library
|
** Basic library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -391,7 +391,7 @@ static int luaB_select (lua_State *L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int finishpcall (lua_State *L, int status, int isx) {
|
static int finishpcall (lua_State *L, int status) {
|
||||||
if (!lua_checkstack(L, 1)) { /* no space for extra boolean? */
|
if (!lua_checkstack(L, 1)) { /* no space for extra boolean? */
|
||||||
lua_settop(L, 0); /* create space for return values */
|
lua_settop(L, 0); /* create space for return values */
|
||||||
lua_pushboolean(L, 0);
|
lua_pushboolean(L, 0);
|
||||||
|
@ -399,27 +399,24 @@ static int finishpcall (lua_State *L, int status, int isx) {
|
||||||
return 2; /* return false, msg */
|
return 2; /* return false, msg */
|
||||||
}
|
}
|
||||||
lua_pushboolean(L, status); /* first result (status) */
|
lua_pushboolean(L, status); /* first result (status) */
|
||||||
if (isx) /* came from xpcall? */
|
lua_replace(L, 1); /* put first result in first slot */
|
||||||
lua_replace(L, 1); /* put first result in place of error function */
|
|
||||||
else /* came from pcall */
|
|
||||||
lua_insert(L, 1); /* insert first result before the others */
|
|
||||||
return lua_gettop(L);
|
return lua_gettop(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int pcallcont (lua_State *L) {
|
static int pcallcont (lua_State *L) {
|
||||||
int isx = 0; /* =0 to avoid warnings */
|
int status = lua_getctx(L, NULL);
|
||||||
int status = lua_getctx(L, &isx);
|
return finishpcall(L, (status == LUA_YIELD));
|
||||||
lua_assert(status != LUA_OK);
|
|
||||||
return finishpcall(L, (status == LUA_YIELD), isx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int luaB_pcall (lua_State *L) {
|
static int luaB_pcall (lua_State *L) {
|
||||||
int status;
|
int status;
|
||||||
luaL_checkany(L, 1);
|
luaL_checkany(L, 1);
|
||||||
status = lua_pcallk(L, lua_gettop(L) - 1, LUA_MULTRET, 0, 0, pcallcont);
|
lua_pushnil(L);
|
||||||
return finishpcall(L, (status == LUA_OK), 0);
|
lua_insert(L, 1); /* create space for status result */
|
||||||
|
status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, pcallcont);
|
||||||
|
return finishpcall(L, (status == LUA_OK));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -430,8 +427,8 @@ static int luaB_xpcall (lua_State *L) {
|
||||||
lua_pushvalue(L, 1); /* exchange function... */
|
lua_pushvalue(L, 1); /* exchange function... */
|
||||||
lua_copy(L, 2, 1); /* ...and error handler */
|
lua_copy(L, 2, 1); /* ...and error handler */
|
||||||
lua_replace(L, 2);
|
lua_replace(L, 2);
|
||||||
status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 1, pcallcont);
|
status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 0, pcallcont);
|
||||||
return finishpcall(L, (status == LUA_OK), 1);
|
return finishpcall(L, (status == LUA_OK));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue