From: Wieger Opmeer Date: Fri, 15 Jan 2016 13:43:12 +0000 (+0100) Subject: Fix importing of standard libraries for Lua version >= 5.2; Change some lua_pushnumbe... X-Git-Tag: dnsdist-1.0.0-alpha2~65^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F3243%2Fhead;p=thirdparty%2Fpdns.git Fix importing of standard libraries for Lua version >= 5.2; Change some lua_pushnumbers to lua_pushinteger because Lua 5.3 has native integers --- diff --git a/modules/luabackend/lua_functions.cc b/modules/luabackend/lua_functions.cc index 67aabfe9b7..2df88746ca 100644 --- a/modules/luabackend/lua_functions.cc +++ b/modules/luabackend/lua_functions.cc @@ -30,8 +30,14 @@ #include using namespace std; +// It seems we don't want the coroutine standard library so we can't use +// luaL_openlibs(). FIXME: is the coroutine library really that bad? const luaL_Reg lualibs[] = { +#if LUA_VERSION_NUM < 502 {"", luaopen_base}, +#else + {"_G", luaopen_base}, +#endif {LUA_LOADLIBNAME, luaopen_package}, {LUA_TABLIBNAME, luaopen_table}, {LUA_IOLIBNAME, luaopen_io}, @@ -39,6 +45,12 @@ const luaL_Reg lualibs[] = { {LUA_STRLIBNAME, luaopen_string}, {LUA_MATHLIBNAME, luaopen_math}, {LUA_DBLIBNAME, luaopen_debug}, +#if LUA_VERSION_NUM == 502 || defined(LUA_COMPAT_BITLIB) + {LUA_BITLIBNAME, luaopen_bit32}, +#endif +#if LUA_VERSION_NUM == 503 + {LUA_UTF8LIBNAME, luaopen_utf8}, +#endif // {LUA_COLIBNAME, luaopen_coroutine}, #ifdef USE_LUAJIT {"bit", luaopen_bit}, @@ -109,7 +121,7 @@ int l_dnspacket (lua_State *lua) { } lua_pushstring(lua, lb->dnspacket->getRemote().c_str()); - lua_pushnumber(lua, lb->dnspacket->getRemotePort()); + lua_pushinteger(lua, lb->dnspacket->getRemotePort()); lua_pushstring(lua, lb->dnspacket->getLocal().c_str()); lua_pushstring(lua, lb->dnspacket->getRealRemote().toString().c_str()); @@ -151,9 +163,14 @@ void register_lua_functions(lua_State *lua) { const luaL_Reg *lib = lualibs; for (; lib->func; lib++) { +#if LUA_VERSION_NUM < 502 lua_pushcfunction(lua, lib->func); lua_pushstring(lua, lib->name); lua_call(lua, 1, 0); +#else + luaL_requiref(lua, lib->name, lib->func, 1); + lua_pop(lua, 1); /* remove lib */ +#endif } lua_gc(lua, LUA_GCRESTART, 0); @@ -199,10 +216,10 @@ void register_lua_functions(lua_State *lua) { lua_newtable(lua); for(vector::const_iterator iter = QType::names.begin(); iter != QType::names.end(); ++iter) { - lua_pushnumber(lua, iter->second); + lua_pushinteger(lua, iter->second); lua_setfield(lua, -2, iter->first.c_str()); } - lua_pushnumber(lua, 3); + lua_pushinteger(lua, 3); lua_setfield(lua, -2, "NXDOMAIN"); lua_setglobal(lua, "QTypes"); } @@ -240,7 +257,7 @@ bool LUABackend::getValueFromTable(lua_State *lua, const std::string& key, DNSNa } bool LUABackend::getValueFromTable(lua_State *lua, uint32_t key, string& value) { - lua_pushnumber(lua, key); + lua_pushinteger(lua, key); lua_gettable(lua, -2); bool ret = false; diff --git a/modules/luabackend/minimal.cc b/modules/luabackend/minimal.cc index ec09913776..f048614cd0 100644 --- a/modules/luabackend/minimal.cc +++ b/modules/luabackend/minimal.cc @@ -68,7 +68,7 @@ bool LUABackend::list(const DNSName &target, int domain_id, bool include_disable lua_rawgeti(lua, LUA_REGISTRYINDEX, f_lua_list); lua_pushstring(lua, target.toString().c_str()); - lua_pushnumber(lua, domain_id); + lua_pushinteger(lua, domain_id); if(lua_pcall(lua, 2, 1, f_lua_exec_error) != 0) { string e = backend_name + lua_tostring(lua, -1); @@ -102,7 +102,7 @@ void LUABackend::lookup(const QType &qtype, const DNSName &qname, DNSPacket *p, // lua_pushnumber(lua, qtype.getCode()); lua_pushstring(lua, qtype.getName().c_str()); lua_pushstring(lua, qname.toString(). c_str()); - lua_pushnumber(lua, domain_id); + lua_pushinteger(lua, domain_id); if(lua_pcall(lua, 3, 0, f_lua_exec_error) != 0) { string e = backend_name + lua_tostring(lua, -1);