]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Rspamadm lua: support passing command line arguments to Lua 1386/head
authorAndrew Lewis <nerf@judo.za.org>
Tue, 31 Jan 2017 11:12:51 +0000 (13:12 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Tue, 31 Jan 2017 11:12:51 +0000 (13:12 +0200)
src/rspamadm/lua_repl.c

index 0245617338b5f2a4a03ebd017903029c0050c69f..2f6ee5676a89d89341dea0ac277b844f78d14384 100644 (file)
@@ -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)) {