aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-01-10 22:43:28 +0000
committerMatthew Wild <mwild1@gmail.com>2010-01-10 22:43:28 +0000
commit54f7dc1d2f0acd03c0682f2c98506a317eff4349 (patch)
tree6a7778bb41899950aaf07b02b2eeac99b62e8cb2
parentdf44b24491dbe81bcdeb3c161bbb2f44f3bb0439 (diff)
downloadprosody-54f7dc1d2f0acd03c0682f2c98506a317eff4349.tar.gz
prosody-54f7dc1d2f0acd03c0682f2c98506a317eff4349.zip
util.pposix: Replace the unwieldy module table generation with luaL_register() call - side effect - it now sets the pposix global to the module table
-rw-r--r--util-src/pposix.c51
1 files changed, 18 insertions, 33 deletions
diff --git a/util-src/pposix.c b/util-src/pposix.c
index b47faaaf..49521a16 100644
--- a/util-src/pposix.c
+++ b/util-src/pposix.c
@@ -486,47 +486,32 @@ int lc_abort(lua_State* L)
int luaopen_util_pposix(lua_State *L)
{
- lua_newtable(L);
+ luaL_Reg exports[] = {
+ { "abort", lc_abort },
- lua_pushcfunction(L, lc_abort);
- lua_setfield(L, -2, "abort");
+ { "daemonize", lc_daemonize },
- lua_pushcfunction(L, lc_daemonize);
- lua_setfield(L, -2, "daemonize");
+ { "syslog_open", lc_syslog_open },
+ { "syslog_close", lc_syslog_close },
+ { "syslog_log", lc_syslog_log },
+ { "syslog_setminlevel", lc_syslog_setmask },
- lua_pushcfunction(L, lc_syslog_open);
- lua_setfield(L, -2, "syslog_open");
+ { "getpid", lc_getpid },
+ { "getuid", lc_getuid },
+ { "getgid", lc_getgid },
- lua_pushcfunction(L, lc_syslog_close);
- lua_setfield(L, -2, "syslog_close");
+ { "setuid", lc_setuid },
+ { "setgid", lc_setgid },
- lua_pushcfunction(L, lc_syslog_log);
- lua_setfield(L, -2, "syslog_log");
+ { "umask", lc_umask },
- lua_pushcfunction(L, lc_syslog_setmask);
- lua_setfield(L, -2, "syslog_setminlevel");
+ { "setrlimit", lc_setrlimit },
+ { "getrlimit", lc_getrlimit },
- lua_pushcfunction(L, lc_getpid);
- lua_setfield(L, -2, "getpid");
+ { NULL, NULL }
+ };
- lua_pushcfunction(L, lc_getuid);
- lua_setfield(L, -2, "getuid");
- lua_pushcfunction(L, lc_getgid);
- lua_setfield(L, -2, "getgid");
-
- lua_pushcfunction(L, lc_setuid);
- lua_setfield(L, -2, "setuid");
- lua_pushcfunction(L, lc_setgid);
- lua_setfield(L, -2, "setgid");
-
- lua_pushcfunction(L, lc_umask);
- lua_setfield(L, -2, "umask");
-
- lua_pushcfunction(L, lc_setrlimit);
- lua_setfield(L, -2, "setrlimit");
-
- lua_pushcfunction(L, lc_getrlimit);
- lua_setfield(L, -2, "getrlimit");
+ luaL_register(L, "pposix", exports);
lua_pushliteral(L, "pposix");
lua_setfield(L, -2, "_NAME");