about summary refs log tree commit diff stats
path: root/src/lbaselib.c
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-02-18 18:00:58 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-02-18 18:00:58 -0800
commitb8cba84d2037718cb14f49eeb3ccab47a68e6827 (patch)
tree3f8a7a60f22b89696e26e2dcfe2cd675e96e2e0c /src/lbaselib.c
parent24db182620b89a9b3480031b0a99c73a8f4d0c3b (diff)
downloadteliva-b8cba84d2037718cb14f49eeb3ccab47a68e6827.tar.gz
bring back pcall and xpcall
They aren't evaluating strings after all.
Diffstat (limited to 'src/lbaselib.c')
-rw-r--r--src/lbaselib.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lbaselib.c b/src/lbaselib.c
index 3c051f0..8a4d651 100644
--- a/src/lbaselib.c
+++ b/src/lbaselib.c
@@ -304,6 +304,28 @@ static int luaB_select (lua_State *L) {
 }
 
 
+static int luaB_pcall (lua_State *L) {
+  int status;
+  luaL_checkany(L, 1);
+  status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0);
+  lua_pushboolean(L, (status == 0));
+  lua_insert(L, 1);
+  return lua_gettop(L);  /* return status + all results */
+}
+
+
+static int luaB_xpcall (lua_State *L) {
+  int status;
+  luaL_checkany(L, 2);
+  lua_settop(L, 2);
+  lua_insert(L, 1);  /* put error function under function to be called */
+  status = lua_pcall(L, 0, LUA_MULTRET, 1);
+  lua_pushboolean(L, (status == 0));
+  lua_replace(L, 1);
+  return lua_gettop(L);  /* return status + all results */
+}
+
+
 static int luaB_tostring (lua_State *L) {
   luaL_checkany(L, 1);
   if (luaL_callmeta(L, 1, "__tostring"))  /* is there a metafield? */
@@ -363,6 +385,7 @@ static const luaL_Reg base_funcs[] = {
   {"getfenv", luaB_getfenv},
   {"getmetatable", luaB_getmetatable},
   {"next", luaB_next},
+  {"pcall", luaB_pcall},
   {"print", luaB_print},
   {"rawequal", luaB_rawequal},
   {"rawget", luaB_rawget},
@@ -374,6 +397,7 @@ static const luaL_Reg base_funcs[] = {
   {"tostring", luaB_tostring},
   {"type", luaB_type},
   {"unpack", luaB_unpack},
+  {"xpcall", luaB_xpcall},
   {NULL, NULL}
 };