Software /
code /
prosody
Diff
util-src/pposix.c @ 2441:d72078946a16
util.pposix: Replace the unwieldy module table generation with luaL_register() call - side effect - it now sets the pposix global to the module table
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 10 Jan 2010 22:43:28 +0000 |
parent | 2438:819ba949c7bc |
child | 2443:b335ae55af77 |
line wrap: on
line diff
--- a/util-src/pposix.c Sun Jan 10 22:15:15 2010 +0000 +++ b/util-src/pposix.c Sun Jan 10 22:43:28 2010 +0000 @@ -486,47 +486,32 @@ 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"); - - lua_pushcfunction(L, lc_daemonize); - lua_setfield(L, -2, "daemonize"); + { "daemonize", lc_daemonize }, - lua_pushcfunction(L, lc_syslog_open); - lua_setfield(L, -2, "syslog_open"); - - lua_pushcfunction(L, lc_syslog_close); - lua_setfield(L, -2, "syslog_close"); - - lua_pushcfunction(L, lc_syslog_log); - lua_setfield(L, -2, "syslog_log"); - - lua_pushcfunction(L, lc_syslog_setmask); - lua_setfield(L, -2, "syslog_setminlevel"); + { "syslog_open", lc_syslog_open }, + { "syslog_close", lc_syslog_close }, + { "syslog_log", lc_syslog_log }, + { "syslog_setminlevel", lc_syslog_setmask }, - lua_pushcfunction(L, lc_getpid); - lua_setfield(L, -2, "getpid"); + { "getpid", lc_getpid }, + { "getuid", lc_getuid }, + { "getgid", lc_getgid }, - lua_pushcfunction(L, lc_getuid); - lua_setfield(L, -2, "getuid"); - lua_pushcfunction(L, lc_getgid); - lua_setfield(L, -2, "getgid"); + { "setuid", lc_setuid }, + { "setgid", lc_setgid }, - lua_pushcfunction(L, lc_setuid); - lua_setfield(L, -2, "setuid"); - lua_pushcfunction(L, lc_setgid); - lua_setfield(L, -2, "setgid"); + { "umask", lc_umask }, + + { "setrlimit", lc_setrlimit }, + { "getrlimit", lc_getrlimit }, - lua_pushcfunction(L, lc_umask); - lua_setfield(L, -2, "umask"); + { NULL, NULL } + }; - 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");