diff options
author | sanine <sanine.not@pm.me> | 2022-01-04 23:18:10 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-01-04 23:18:10 -0600 |
commit | 78ee0de29b46f5faed6ca2ae5222c64fbd9a2c1e (patch) | |
tree | 02122654d8b360471760b8e4809151ca6c60c02a /src/argent.c | |
parent | 72e13dff9ff4fde91b84054167da91a5d27cb952 (diff) |
allow overriding the builtin script
Diffstat (limited to 'src/argent.c')
-rw-r--r-- | src/argent.c | 17 |
1 files changed, 15 insertions, 2 deletions
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"); |