diff options
Diffstat (limited to 'src/argent.c')
-rw-r--r-- | src/argent.c | 62 |
1 files changed, 50 insertions, 12 deletions
diff --git a/src/argent.c b/src/argent.c index fb0d37b..adf6230 100644 --- a/src/argent.c +++ b/src/argent.c @@ -2,8 +2,6 @@ #include <lualib.h> #include <lauxlib.h> -#include "honeysuckle.h" - #include "options.h" #include "bindings.h" #include "logging.h" @@ -25,6 +23,9 @@ struct settings { } while(0) +int hs_call(lua_State *L, int nargs, int nret); + + int main(int argc, char **argv) { argent_log(DEBUG, "parse command-line options"); @@ -45,16 +46,16 @@ int main(int argc, char **argv) luaL_openlibs(L); argent_log(DEBUG, "create argent table"); - hs_create_table - (L, - hs_str_cfunc("markdown", markdown), - hs_str_cfunc("currentWorkingDirectory", current_working_directory), - hs_str_cfunc("scanDirectory", scan_directory), - hs_str_cfunc("createDirectory", create_directory), - hs_str_cfunc("copyFile", copy_file), - hs_str_cfunc("log", argent_log_lua) - ); - lua_setglobal(L, "argent"); + luaL_Reg tbl[] = { + {"markdown", markdown}, + {"currentWorkingDirectory", current_working_directory}, + {"scanDirectory", scan_directory}, + {"createDirectory", create_directory}, + {"copyFile", copy_file}, + {"log", argent_log_lua}, + {NULL, NULL}, + }; + luaL_register(L, "argent", tbl); // load argent lua script argent_log(DEBUG, "load main lua script"); @@ -90,3 +91,40 @@ int main(int argc, char **argv) lua_close(L); return 0; } + + +int hs_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 hs_call(lua_State *L, int nargs, int nret) +{ + int traceback_pos = lua_gettop(L) - nargs; + lua_pushcfunction(L, hs_traceback); + lua_insert(L, traceback_pos); + + int result = lua_pcall(L, nargs, nret, traceback_pos); + lua_remove(L, traceback_pos); + return result; +} |