]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
engine: added ‘hostname()’ to Lua engine
authorMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 12 Apr 2015 19:49:12 +0000 (21:49 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 12 Apr 2015 19:49:12 +0000 (21:49 +0200)
daemon/engine.c

index ff6ca6584c38cbef08b5dc8f53586915e4638623..b1eea15d63887a5c31039de445a4df01965d6dcc 100644 (file)
@@ -41,15 +41,10 @@ static int l_help(lua_State *L)
        static const char *help_str =
                "help()\n    show this help\n"
                "quit()\n    quit\n"
-               "modules.list()\n    list modules\n"
-               "modules.load()\n    load module\n"
-               "modules.unload()\n    unload module\n"
-               "cache.open(path, max_size)\n    open cache\n"
-               "cache.close()\n    close cache\n"
+               "hostname()\n    hostname\n"
                ;
-       puts(help_str);
-       /* No results */
-       return 0;
+       lua_pushstring(L, help_str);
+       return 1;
 }
 
 /** Quit current executable. */
@@ -61,6 +56,15 @@ static int l_quit(lua_State *L)
        return 0;
 }
 
+/** Return hostname. */
+static int l_hostname(lua_State *L)
+{
+       char host_str[KNOT_DNAME_MAXLEN];
+       gethostname(host_str, sizeof(host_str));
+       lua_pushstring(L, host_str);
+       return 1;
+}
+
 /** Trampoline function for module properties. */
 static int l_trampoline(lua_State *L)
 {
@@ -115,6 +119,8 @@ static int init_state(struct engine *engine)
        lua_setglobal(engine->L, "help");
        lua_pushcfunction(engine->L, l_quit);
        lua_setglobal(engine->L, "quit");
+       lua_pushcfunction(engine->L, l_hostname);
+       lua_setglobal(engine->L, "hostname");
        lua_pushlightuserdata(engine->L, engine);
        lua_setglobal(engine->L, "__engine");
        return kr_ok();