diff options
Diffstat (limited to 'src/l_util.c')
-rw-r--r-- | src/l_util.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/l_util.c b/src/l_util.c index dbe43a5..6f55000 100644 --- a/src/l_util.c +++ b/src/l_util.c @@ -44,6 +44,10 @@ #include "l_util.h" +#if LUA_VERSION_NUM < 502 +#define lua_objlen lua_rawlen +#endif + static int get_fd(lua_State *L) { if(!lua_istable(L, -1)) @@ -141,7 +145,7 @@ static char** table_to_argv(lua_State *L, const char* script, int index) { size_t n = 0; if(lua_istable(L, index)) - n = lua_objlen(L, index); + n = lua_rawlen(L, index); char** my_ptrptr = malloc((n+2)*sizeof(char*)); if(!my_ptrptr) @@ -178,7 +182,7 @@ static char** table_to_evp(lua_State *L, int index) if(!lua_istable(L, index)) return NULL; - size_t n = lua_objlen(L, index); + size_t n = lua_rawlen(L, index); char** my_ptrptr = malloc((n+1)*sizeof(char*)); if(!my_ptrptr) return NULL; @@ -445,7 +449,7 @@ static int l_util_kill(lua_State *L) return 1; } -static const struct luaL_reg util_funcs [] = { +static const struct luaL_Reg util_funcs [] = { { "select", l_util_select }, { "exec", l_util_exec }, { "waitpid", l_util_waitpid }, @@ -456,8 +460,14 @@ static const struct luaL_reg util_funcs [] = { LUALIB_API int luaopen_util(lua_State *L) { - luaL_register(L, LUA_UTILLIBNAME, util_funcs); +#if LUA_VERSION_NUM > 501 lua_newtable(L); + luaL_setfuncs(L, util_funcs, 0); + lua_pushvalue(L, -1); + lua_setglobal(L, LUA_UTILLIBNAME); +#else + luaL_register(L, LUA_UTILLIBNAME, util_funcs); +#endif lua_setfield(L, -2, LUA_UTILCHLIDRENNAME); return 1; } |