Merge 0.9->0.10 again
[prosody.git] / util-src / encodings.c
index 91826ca42f3b682fbd196b5d0ca1e7ad2d256ec0..5fa9706b63bbe306c09ed96fe0cfd3417f85528b 100644 (file)
 #include "lua.h"
 #include "lauxlib.h"
 
+#if (LUA_VERSION_NUM == 502)
+#define luaL_register(L, N, R) luaL_setfuncs(L, R, 0)
+#endif
+
 /***************** BASE64 *****************/
 
 static const char code[]=
@@ -448,40 +452,30 @@ static const luaL_Reg Reg_idna[] =
 
 /***************** end *****************/
 
-static const luaL_Reg Reg[] =
-{
-       { NULL,         NULL    }
-};
-
 LUALIB_API int luaopen_util_encodings(lua_State *L)
 {
 #ifdef USE_STRINGPREP_ICU
        init_icu();
 #endif
-       luaL_register(L, "encodings", Reg);
+       lua_newtable(L);
 
-       lua_pushliteral(L, "base64");
        lua_newtable(L);
        luaL_register(L, NULL, Reg_base64);
-       lua_settable(L,-3);
+       lua_setfield(L, -2, "base64");
 
-       lua_pushliteral(L, "stringprep");
        lua_newtable(L);
        luaL_register(L, NULL, Reg_stringprep);
-       lua_settable(L,-3);
+       lua_setfield(L, -2, "stringprep");
 
-       lua_pushliteral(L, "idna");
        lua_newtable(L);
        luaL_register(L, NULL, Reg_idna);
-       lua_settable(L,-3);
+       lua_setfield(L, -2, "idna");
 
-       lua_pushliteral(L, "utf8");
        lua_newtable(L);
        luaL_register(L, NULL, Reg_utf8);
-       lua_settable(L, -3);
+       lua_setfield(L, -2, "utf8");
 
-       lua_pushliteral(L, "version");                  /** version */
        lua_pushliteral(L, "-3.14");
-       lua_settable(L,-3);
+       lua_setfield(L, -2, "version");
        return 1;
 }