diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-01-08 18:03:02 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-01-09 01:13:43 +0100 |
commit | 2594084de6e163f15a1516d64cf413de5b0d899f (patch) | |
tree | e1843432693884c40df876aa6ddc26ee5e6e78a5 | |
parent | f8cabbd458ed3658ca0e933bd52e29d857f594e2 (diff) | |
download | manaserv-2594084de6e163f15a1516d64cf413de5b0d899f.tar.gz manaserv-2594084de6e163f15a1516d64cf413de5b0d899f.tar.bz2 manaserv-2594084de6e163f15a1516d64cf413de5b0d899f.tar.xz manaserv-2594084de6e163f15a1516d64cf413de5b0d899f.zip |
Added support for Lua 5.2
Should still work against Lua 5.1 as well.
-rw-r--r-- | src/scripting/lua.cpp | 9 | ||||
-rw-r--r-- | src/scripting/luascript.cpp | 4 | ||||
-rw-r--r-- | src/scripting/luautil.h | 11 |
3 files changed, 23 insertions, 1 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 6285f382..c0aedfdd 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -2575,7 +2575,11 @@ LuaScript::LuaScript(): // Register package loader that goes through the resource manager // table.insert(package.loaders, 2, require_loader) lua_getglobal(mRootState, "package"); +#if LUA_VERSION_NUM < 502 lua_getfield(mRootState, -1, "loaders"); +#else + lua_getfield(mRootState, -1, "searchers"); +#endif lua_pushcfunction(mRootState, require_loader); lua_rawseti(mRootState, -2, 2); lua_pop(mRootState, 2); @@ -2699,8 +2703,13 @@ LuaScript::LuaScript(): { "get_special_info", &get_special_info }, { NULL, NULL } }; +#if LUA_VERSION_NUM < 502 lua_pushvalue(mRootState, LUA_GLOBALSINDEX); luaL_register(mRootState, NULL, callbacks); +#else + lua_pushglobaltable(mRootState); + luaL_setfuncs(mRootState, callbacks, 0); +#endif lua_pop(mRootState, 1); // pop the globals table static luaL_Reg const members_AttackInfo[] = { diff --git a/src/scripting/luascript.cpp b/src/scripting/luascript.cpp index 97b03e1d..a3dcb1d4 100644 --- a/src/scripting/luascript.cpp +++ b/src/scripting/luascript.cpp @@ -151,7 +151,11 @@ bool LuaScript::resume() setMap(mCurrentThread->mMap); const int tmpNbArgs = nbArgs; nbArgs = -1; +#if LUA_VERSION_NUM < 502 int result = lua_resume(mCurrentState, tmpNbArgs); +#else + int result = lua_resume(mCurrentState, NULL, tmpNbArgs); +#endif setMap(0); if (result == 0) // Thread is done diff --git a/src/scripting/luautil.h b/src/scripting/luautil.h index 1ff2ab8d..0d2a981d 100644 --- a/src/scripting/luautil.h +++ b/src/scripting/luautil.h @@ -103,7 +103,12 @@ public: luaL_newmetatable(s, mTypeName); // metatable lua_pushstring(s, "__index"); // metatable, "__index" - luaL_register(s, typeName, members); // metatable, "__index", {} + lua_createtable(s, 0, 0); // metatable, "__index", {} +#if LUA_VERSION_NUM < 502 + luaL_register(s, NULL, members); +#else + luaL_setfuncs(s, members, 0); +#endif lua_rawset(s, -3); // metatable lua_pop(s, 1); // -empty- } @@ -125,8 +130,12 @@ public: void *userData = lua_newuserdata(s, sizeof(T*)); * static_cast<T**>(userData) = object; +#if LUA_VERSION_NUM < 502 luaL_newmetatable(s, mTypeName); lua_setmetatable(s, -2); +#else + luaL_setmetatable(s, mTypeName); +#endif UserDataCache::insert(s, object); } |