diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-31 17:47:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-31 17:47:10 +0000 |
commit | 2c3d38f507cfe7410a763d4f7c9af278184fcc44 (patch) | |
tree | caee2167cc5f952f0298056c85063e4499dc2e47 | |
parent | 712d1dc173dce57404f5909096bae30187e3f469 (diff) | |
parent | bf0348f2226764ee477d90244dd8e0023889ee9d (diff) | |
download | rspamd-2c3d38f507cfe7410a763d4f7c9af278184fcc44.tar.gz rspamd-2c3d38f507cfe7410a763d4f7c9af278184fcc44.zip |
Merge pull request #1386 from fatalbanana/branch
[Minor] Rspamadm lua: support passing command line arguments to Lua
-rw-r--r-- | src/rspamadm/lua_repl.c | 16 |
1 files changed, 16 insertions, 0 deletions
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)) { |