From bf0348f2226764ee477d90244dd8e0023889ee9d Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Tue, 31 Jan 2017 13:12:51 +0200 Subject: [PATCH] [Minor] Rspamadm lua: support passing command line arguments to Lua --- src/rspamadm/lua_repl.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/rspamadm/lua_repl.c b/src/rspamadm/lua_repl.c index 024561733..2f6ee5676 100644 --- a/src/rspamadm/lua_repl.c +++ b/src/rspamadm/lua_repl.c @@ -32,6 +32,7 @@ static gchar **paths = NULL; static gchar **scripts = NULL; +static gchar **lua_args = NULL; static gchar *histfile = NULL; static guint max_history = 2000; static gchar *serve = NULL; @@ -109,6 +110,8 @@ static GOptionEntry entries[] = { "Serve http lua server", NULL}, {"batch", 'b', 0, G_OPTION_ARG_NONE, &batch, "Batch execution mode", NULL}, + {"args", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &lua_args, + "Arguments to pass to Lua", NULL}, {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL} }; @@ -124,6 +127,7 @@ rspamadm_lua_help (gboolean full_help) "-p: add additional lua paths (may be repeated)\n" "-s: load scripts on start from specified files (may be repeated)\n" "-S: listen on a specified address as HTTP server\n" + "-a: pass argument to lua (may be repeated)\n" "--help: shows available options and commands"; } else { @@ -682,6 +686,18 @@ rspamadm_lua (gint argc, gchar **argv) } } + if (lua_args) { + int i = 1; + lua_newtable (L); + for (elt = lua_args; *elt != NULL; elt ++) { + lua_pushnumber(L, i); + lua_pushstring(L, *elt); + lua_settable (L, -3); + i++; + } + lua_setglobal (L, "arg"); + } + if (scripts) { for (elt = scripts; *elt != NULL; elt ++) { if (!rspamadm_lua_load_script (L, *elt)) { -- 2.39.5