summaryrefslogtreecommitdiff
path: root/src/util/util.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-02-24 04:06:36 -0600
committersanine <sanine.not@pm.me>2023-02-24 04:06:36 -0600
commit2fa0047f4600ef95d32e864dd7c54e99e27265fe (patch)
treee592d63a38c087f8da7360a6df7e5904ca831dc8 /src/util/util.c
parent98c6064fc679586251793ae47c3c6f57dd4d1cb1 (diff)
refactor: bind (almost) all ode functions
Diffstat (limited to 'src/util/util.c')
-rw-r--r--src/util/util.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/util/util.c b/src/util/util.c
index 6f1ee44..564ffd4 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -76,3 +76,40 @@ int gc_canary_collect(lua_State *L)
luaL_unref(L, LUA_REGISTRYINDEX, *canary);
return 0;
}
+
+
+static int h_traceback(lua_State *L)
+{
+ if (!lua_isstring(L, 1))
+ /* 'message' is not a string, keep intact */
+ return 1;
+
+ lua_getglobal(L, "debug");
+ if (!lua_istable(L, -1)) {
+ lua_pop(L, 1);
+ return 1;
+ }
+
+ lua_getfield(L, -1, "traceback");
+ if (!lua_isfunction(L, -1)) {
+ lua_pop(L, 2);
+ return 1;
+ }
+
+ lua_pushvalue(L, 1);
+ lua_pushinteger(L, 2);
+ lua_call(L, 2, 1);
+ return 1;
+}
+
+
+int h_call(lua_State *L, int nargs, int nret)
+{
+ int traceback_pos = lua_gettop(L) - nargs;
+ lua_pushcfunction(L, h_traceback);
+ lua_insert(L, traceback_pos);
+
+ int result = lua_pcall(L, nargs, nret, traceback_pos);
+ lua_remove(L, traceback_pos);
+ return result;
+}