# HG changeset patch # User Matthew Wild # Date 1263163408 0 # Node ID d72078946a167d2e1693aeb2bb9d9afea5a77c04 # Parent 11e3d16a128f8e4456e04552792ce7c7fa7dcb8e util.pposix: Replace the unwieldy module table generation with luaL_register() call - side effect - it now sets the pposix global to the module table diff -r 11e3d16a128f -r d72078946a16 util-src/pposix.c --- 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");