From 78ee0de29b46f5faed6ca2ae5222c64fbd9a2c1e Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 4 Jan 2022 23:18:10 -0600 Subject: allow overriding the builtin script --- src/argent.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/argent.c') diff --git a/src/argent.c b/src/argent.c index f057380..fb0d37b 100644 --- a/src/argent.c +++ b/src/argent.c @@ -36,6 +36,9 @@ 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); + if (opts.script_filename != NULL) { + argent_log(INFO, "script override: %s", opts.script_filename); + } argent_log(DEBUG, "create lua state"); lua_State *L = luaL_newstate(); @@ -55,8 +58,18 @@ int main(int argc, char **argv) // load argent lua script argent_log(DEBUG, "load main lua script"); - error = luaL_dostring(L, argent_script); - CHECK_LUA_ERROR(); + if (opts.script_filename == NULL) { + error = luaL_dostring(L, argent_script); + CHECK_LUA_ERROR(); + } + else { + error = luaL_dofile(L, opts.script_filename); + CHECK_LUA_ERROR(); + if (!lua_isfunction(L, -1)) { + argent_log(FATAL, "override script '%s' did not return a function!", opts.script_filename); + return 1; + } + } // load configuration file argent_log(DEBUG, "load configuration file"); -- cgit v1.2.1