summaryrefslogtreecommitdiff
path: root/src/argent.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/argent.c')
-rw-r--r--src/argent.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/argent.c b/src/argent.c
index ae3a717..0d0dca2 100644
--- a/src/argent.c
+++ b/src/argent.c
@@ -7,6 +7,7 @@
#include "options.h"
#include "bindings.h"
#include "logging.h"
+#include "lua-script/script.h"
struct settings {
@@ -14,6 +15,16 @@ struct settings {
};
+#define CHECK_LUA_ERROR() \
+ do { \
+ if (error != 0) { \
+ argent_log(FATAL, "lua_error: %s", lua_tostring(L, -1)); \
+ lua_close(L); \
+ return error; \
+ } \
+ } while(0)
+
+
int main(int argc, char **argv)
{
argent_log(DEBUG, "parse command-line options");
@@ -24,7 +35,6 @@ int main(int argc, char **argv)
argent_log(INFO, "log level: %s", level_string(argent_log_level));
argent_log(INFO, "configuration file: %s", opts.conf_filename);
- argent_log(INFO, "output directory: %s", opts.output_dir);
argent_log(DEBUG, "create lua state");
lua_State *L = luaL_newstate();
@@ -40,20 +50,25 @@ int main(int argc, char **argv)
);
lua_setglobal(L, "argent");
+ // load argent lua script
+ argent_log(DEBUG, "load main lua script");
+ error = luaL_dostring(L, argent_script);
+ CHECK_LUA_ERROR();
+
+ // load configuration file
argent_log(DEBUG, "load configuration file");
error = luaL_loadfile(L, opts.conf_filename);
- if (error != 0) {
- argent_log(FATAL, "lua error: %s", lua_tostring(L, -1));
- lua_close(L);
- return error;
- }
+ CHECK_LUA_ERROR();
+
+ // push config table to stack
argent_log(DEBUG, "run configuration file");
error = hs_call(L, 0, 1);
- if (error != 0) {
- argent_log(FATAL, "lua error: %s", lua_tostring(L, -1));
- lua_close(L);
- return error;
- }
+ CHECK_LUA_ERROR();
+
+ // run argent script
+ argent_log(DEBUG, "run main lua script");
+ error = hs_call(L, 1, 0);
+ CHECK_LUA_ERROR();
argent_log(DEBUG, "close lua state");
lua_close(L);