diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-06 09:39:48 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-06 09:39:48 -0300 |
commit | f1c43bbe19026b80b5185cbdd6dec6230028a999 (patch) | |
tree | b9b6afdda3f6eb31f286127c4da58792868747b6 | |
parent | 5a8f383e60543962c972f5b2c188a6aef4364c46 (diff) | |
download | lua-f1c43bbe19026b80b5185cbdd6dec6230028a999.tar.gz lua-f1c43bbe19026b80b5185cbdd6dec6230028a999.tar.bz2 lua-f1c43bbe19026b80b5185cbdd6dec6230028a999.zip |
new function `xpcall' (at least for now...)
-rw-r--r-- | lbaselib.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.77 2002/06/05 16:59:21 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.78 2002/06/05 17:24:04 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 | */ |
@@ -96,7 +96,8 @@ static int luaB_metatable (lua_State *L) { | |||
96 | else { | 96 | else { |
97 | int t = lua_type(L, 2); | 97 | int t = lua_type(L, 2); |
98 | luaL_check_type(L, 1, LUA_TTABLE); | 98 | luaL_check_type(L, 1, LUA_TTABLE); |
99 | luaL_arg_check(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil/table expected"); | 99 | luaL_arg_check(L, t == LUA_TNIL || t == LUA_TTABLE, 2, |
100 | "nil or table expected"); | ||
100 | lua_settop(L, 2); | 101 | lua_settop(L, 2); |
101 | lua_setmetatable(L, 1); | 102 | lua_setmetatable(L, 1); |
102 | } | 103 | } |
@@ -224,7 +225,7 @@ static int luaB_unpack (lua_State *L) { | |||
224 | } | 225 | } |
225 | 226 | ||
226 | 227 | ||
227 | static int luaB_pcall (lua_State *L) { | 228 | static int luaB_xpcall (lua_State *L) { |
228 | int status; | 229 | int status; |
229 | luaL_check_any(L, 1); | 230 | luaL_check_any(L, 1); |
230 | luaL_check_any(L, 2); | 231 | luaL_check_any(L, 2); |
@@ -239,6 +240,20 @@ static int luaB_pcall (lua_State *L) { | |||
239 | } | 240 | } |
240 | 241 | ||
241 | 242 | ||
243 | static int luaB_pcall (lua_State *L) { | ||
244 | int status; | ||
245 | luaL_check_any(L, 1); | ||
246 | status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0); | ||
247 | if (status != 0) | ||
248 | return passresults(L, status); | ||
249 | else { | ||
250 | lua_pushboolean(L, 1); | ||
251 | lua_insert(L, 1); | ||
252 | return lua_gettop(L); /* return `true' + all results */ | ||
253 | } | ||
254 | } | ||
255 | |||
256 | |||
242 | static int luaB_tostring (lua_State *L) { | 257 | static int luaB_tostring (lua_State *L) { |
243 | char buff[64]; | 258 | char buff[64]; |
244 | luaL_checkany(L, 1); | 259 | luaL_checkany(L, 1); |
@@ -388,6 +403,7 @@ static const luaL_reg base_funcs[] = { | |||
388 | {"rawget", luaB_rawget}, | 403 | {"rawget", luaB_rawget}, |
389 | {"rawset", luaB_rawset}, | 404 | {"rawset", luaB_rawset}, |
390 | {"pcall", luaB_pcall}, | 405 | {"pcall", luaB_pcall}, |
406 | {"xpcall", luaB_xpcall}, | ||
391 | {"collectgarbage", luaB_collectgarbage}, | 407 | {"collectgarbage", luaB_collectgarbage}, |
392 | {"gcinfo", luaB_gcinfo}, | 408 | {"gcinfo", luaB_gcinfo}, |
393 | {"loadfile", luaB_loadfile}, | 409 | {"loadfile", luaB_loadfile}, |