From 3b9f934b82d4cf65ddee3cbf1bebc65fccd1f10e Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 16 Jun 2013 03:43:45 +0200 Subject: [PATCH] Fixes to compile Ryzom Client with lua 5.2 --- code/nel/include/nel/gui/lua_helper.h | 2 -- code/nel/include/nel/gui/lua_helper_inline.h | 7 +++++-- code/ryzom/client/src/commands.cpp | 2 +- .../client/src/interface_v3/dbctrl_sheet.cpp | 4 ++-- .../client/src/interface_v3/lua_ihm_ryzom.cpp | 10 ++++++--- code/ryzom/client/src/main_loop.cpp | 2 +- .../client/src/r2/dmc/com_lua_module.cpp | 21 ++++++++++++++++--- code/ryzom/client/src/r2/editor.cpp | 6 ++++-- .../ryzom/client/src/session_browser_impl.cpp | 10 ++++----- 9 files changed, 43 insertions(+), 21 deletions(-) diff --git a/code/nel/include/nel/gui/lua_helper.h b/code/nel/include/nel/gui/lua_helper.h index d35a1a6df..69639fc04 100644 --- a/code/nel/include/nel/gui/lua_helper.h +++ b/code/nel/include/nel/gui/lua_helper.h @@ -217,9 +217,7 @@ namespace NLGUI void clear() { setTop(0); } int getTop(); bool empty() { return getTop() == 0; } -#if LUA_VERSION_NUM >= 502 void pushGlobalTable(); -#endif void pushValue(int index); // copie nth element of stack to the top of the stack void remove(int index); // remove nth element of stack void insert(int index); // insert last element of the stack before the given position diff --git a/code/nel/include/nel/gui/lua_helper_inline.h b/code/nel/include/nel/gui/lua_helper_inline.h index 60cb00ec4..01afd142f 100644 --- a/code/nel/include/nel/gui/lua_helper_inline.h +++ b/code/nel/include/nel/gui/lua_helper_inline.h @@ -81,14 +81,17 @@ inline void CLuaState::setTop(int index) lua_settop(_State, index); } -#if LUA_VERSION_NUM >= 502 //================================================================================ inline void CLuaState::pushGlobalTable() { //H_AUTO(Lua_CLuaState_pushGlobalTable) +#if LUA_VERSION_NUM >= 502 lua_pushglobaltable(_State); -} +#else + checkIndex(LUA_GLOBALSINDEX); + lua_pushvalue(_State, LUA_GLOBALSINDEX); #endif +} //================================================================================ inline void CLuaState::pushValue(int index) diff --git a/code/ryzom/client/src/commands.cpp b/code/ryzom/client/src/commands.cpp index 406d554e3..3805122f2 100644 --- a/code/ryzom/client/src/commands.cpp +++ b/code/ryzom/client/src/commands.cpp @@ -5164,7 +5164,7 @@ NLMISC_COMMAND(luaObject, "Dump the content of a lua object", " [max CLuaIHMRyzom::debugInfo(e.what()); return false; } - luaState->pushValue(LUA_GLOBALSINDEX); + luaState->pushGlobalTable(); CLuaObject env; env.pop(*luaState); uint maxDepth; diff --git a/code/ryzom/client/src/interface_v3/dbctrl_sheet.cpp b/code/ryzom/client/src/interface_v3/dbctrl_sheet.cpp index 088bcc571..ae06d0997 100644 --- a/code/ryzom/client/src/interface_v3/dbctrl_sheet.cpp +++ b/code/ryzom/client/src/interface_v3/dbctrl_sheet.cpp @@ -108,7 +108,7 @@ ucstring CControlSheetTooltipInfoWaiter::infoValidated(CDBCtrlSheet* ctrlSheet, CLuaStackRestorer lsr(ls, 0); CLuaIHM::pushReflectableOnStack(*ls, (CReflectableRefPtrTarget *)ctrlSheet); - ls->pushValue(LUA_GLOBALSINDEX); + ls->pushGlobalTable(); CLuaObject game(*ls); game = game["game"]; game.callMethodByNameNoThrow(luaMethodName.c_str(), 1, 1); @@ -3170,7 +3170,7 @@ void CDBCtrlSheet::getContextHelp(ucstring &help) const _PhraseAdapter = new CSPhraseComAdpater; _PhraseAdapter->Phrase = pPM->getPhrase(phraseId); CLuaIHM::pushReflectableOnStack(*ls, _PhraseAdapter); - ls->pushValue(LUA_GLOBALSINDEX); + ls->pushGlobalTable(); CLuaObject game(*ls); game = game["game"]; game.callMethodByNameNoThrow("updatePhraseTooltip", 1, 1); diff --git a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp index 06b0b8557..fe4c6a716 100644 --- a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp +++ b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp @@ -187,9 +187,11 @@ static DECLARE_INTERFACE_USER_FCT(lua) // *** clear return value const std::string retId= "__ui_internal_ret_"; CLuaStackChecker lsc(&ls); + ls.pushGlobalTable(); ls.push(retId); ls.pushNil(); - ls.setTable(LUA_GLOBALSINDEX); + ls.setTable(-3); //pop pop + ls.pop(); // *** execute script @@ -201,8 +203,10 @@ static DECLARE_INTERFACE_USER_FCT(lua) // *** retrieve and convert return value + ls.pushGlobalTable(); ls.push(retId); - ls.getTable(LUA_GLOBALSINDEX); + ls.getTable(-2); + ls.remove(-2); bool ok= false; sint type= ls.type(); if (type==LUA_TBOOLEAN) @@ -370,7 +374,7 @@ void CLuaIHMRyzom::RegisterRyzomFunctions( NLGUI::CLuaState &ls ) ls.registerFunc("SNode", CUICtor::SNode); // *** Register the metatable for access to client.cfg (nb nico this may be more general later -> access to any config file ...) - ls.pushValue(LUA_GLOBALSINDEX); + ls.pushGlobalTable(); CLuaObject globals(ls); CLuaObject clientCfg = globals.newTable("config"); CLuaObject mt = globals.newTable("__cfmt"); diff --git a/code/ryzom/client/src/main_loop.cpp b/code/ryzom/client/src/main_loop.cpp index 45c6b5b3a..2c362aceb 100644 --- a/code/ryzom/client/src/main_loop.cpp +++ b/code/ryzom/client/src/main_loop.cpp @@ -3235,7 +3235,7 @@ class CHandlerDebugUiDumpElementUnderMouse : public IActionHandler if (!lua) return; CLuaStackRestorer lsr(lua, 0); CLuaIHM::pushUIOnStack(*lua, HighlightedDebugUI); - lua->pushValue(LUA_GLOBALSINDEX); + lua->pushGlobalTable(); CLuaObject env(*lua); env["inspect"].callNoThrow(1, 0); } diff --git a/code/ryzom/client/src/r2/dmc/com_lua_module.cpp b/code/ryzom/client/src/r2/dmc/com_lua_module.cpp index 80275d280..b91aca95c 100644 --- a/code/ryzom/client/src/r2/dmc/com_lua_module.cpp +++ b/code/ryzom/client/src/r2/dmc/com_lua_module.cpp @@ -77,7 +77,7 @@ CComLuaModule::CComLuaModule(CDynamicMapClient* client, lua_State *luaState /*= #ifdef LUA_NEVRAX_VERSION _LuaState = lua_open(NULL, NULL); #else - _LuaState = lua_open(); + _LuaState = luaL_newstate(); #endif _LuaOwnerShip = false; luaopen_base(_LuaState); @@ -105,7 +105,7 @@ CComLuaModule::CComLuaModule(CDynamicMapClient* client, lua_State *luaState /*= void CComLuaModule::initLuaLib() { //H_AUTO(R2_CComLuaModule_initLuaLib) - const luaL_reg methods[] = + const luaL_Reg methods[] = { {"updateScenario", CComLuaModule::luaUpdateScenario}, {"requestUpdateRtScenario", CComLuaModule::luaRequestUpdateRtScenario}, @@ -237,7 +237,12 @@ void CComLuaModule::initLuaLib() }; int initialStackSize = lua_gettop(_LuaState); +#if LUA_VERSION_NUM >= 502 + luaL_newlib(_LuaState, methods); + lua_setglobal(_LuaState, R2_LUA_PATH); +#else luaL_openlib(_LuaState, R2_LUA_PATH, methods, 0); +#endif lua_settop(_LuaState, initialStackSize); } @@ -1046,7 +1051,11 @@ void CComLuaModule::setObjectToLua(lua_State* state, CObject* object) { int initialStackSize = lua_gettop(state); +#if LUA_VERSION_NUM >= 502 + lua_pushglobaltable(state); // _G +#else lua_pushvalue(state, LUA_GLOBALSINDEX); // _G +#endif lua_pushstring(state, "r2"); // _G, "r2" lua_gettable(state, -2); // G, r2 @@ -1106,6 +1115,8 @@ void CComLuaModule::setObjectToLua(lua_State* state, CObject* object) } } +#if 0 + // okay! if (0) { @@ -1128,6 +1139,7 @@ void CComLuaModule::setObjectToLua(lua_State* state, CObject* object) } } } +#endif } else { @@ -1147,8 +1159,11 @@ CObject* CComLuaModule::getObjectFromLua(lua_State* state, sint idx) { if (lua_getmetatable(state, -1)) { - +#if LUA_VERSION_NUM >= 502 + lua_pushglobaltable(state); // obj, mt, _G +#else lua_pushvalue(state, LUA_GLOBALSINDEX); // obj, mt, _G +#endif lua_pushstring(state, "r2"); // obj, mt, _G, "r2" diff --git a/code/ryzom/client/src/r2/editor.cpp b/code/ryzom/client/src/r2/editor.cpp index bee527bbd..c27001140 100644 --- a/code/ryzom/client/src/r2/editor.cpp +++ b/code/ryzom/client/src/r2/editor.cpp @@ -2613,7 +2613,7 @@ void CEditor::init(TMode initialMode, TAccessMode accessMode) } // CLuaStackChecker lsc(&getLua()); - getLua().pushValue(LUA_GLOBALSINDEX); + getLua().pushGlobalTable(); _Globals.pop(getLua()); getLua().pushValue(LUA_REGISTRYINDEX); _Registry.pop(getLua()); @@ -3956,9 +3956,11 @@ void CEditor::release() // clear the environment if (CLuaManager::getInstance().getLuaState()) { + getLua().pushGlobalTable(); getLua().push(R2_LUA_PATH); getLua().pushNil(); - getLua().setTable(LUA_GLOBALSINDEX); + getLua().setTable(-3); // pop pop + getLua().pop(); _Globals.release(); _Registry.release(); _ObjectProjectionMetatable.release(); // AJM diff --git a/code/ryzom/client/src/session_browser_impl.cpp b/code/ryzom/client/src/session_browser_impl.cpp index 5cdd69291..1802aefbf 100644 --- a/code/ryzom/client/src/session_browser_impl.cpp +++ b/code/ryzom/client/src/session_browser_impl.cpp @@ -51,7 +51,7 @@ void CSessionBrowserImpl::init(CLuaState *ls) { nlassert(ls); _Lua = ls; - _Lua->pushValue(LUA_GLOBALSINDEX); + _Lua->pushGlobalTable(); CLuaObject game(*_Lua); game = game["game"]; game.setValue("getRingSessionList", luaGetRingSessionList); @@ -759,7 +759,7 @@ void CSessionBrowserImpl::callRingAccessPointMethod(const char *name, int numArg nlassert(name); { CLuaStackRestorer lsr(_Lua, _Lua->getTop() + numResult); - _Lua->pushValue(LUA_GLOBALSINDEX); + _Lua->pushGlobalTable(); CLuaObject rap(*_Lua); rap = rap["RingAccessPoint"]; rap.callMethodByNameNoThrow(name, numArg, numResult); @@ -774,7 +774,7 @@ void CSessionBrowserImpl::callRingCharTrackingMethod(const char *name, int numAr nlassert(name); { CLuaStackRestorer lsr(_Lua, _Lua->getTop() + numResult); - _Lua->pushValue(LUA_GLOBALSINDEX); + _Lua->pushGlobalTable(); CLuaObject rap(*_Lua); rap = rap["CharTracking"]; rap.callMethodByNameNoThrow(name, numArg, numResult); @@ -789,7 +789,7 @@ void CSessionBrowserImpl::callRingPlayerInfoMethod(const char *name, int numArg, nlassert(name); { CLuaStackRestorer lsr(_Lua, _Lua->getTop() + numResult); - _Lua->pushValue(LUA_GLOBALSINDEX); + _Lua->pushGlobalTable(); CLuaObject rap(*_Lua); rap = rap["RingPlayerInfo"]; rap.callMethodByNameNoThrow(name, numArg, numResult); @@ -804,7 +804,7 @@ void CSessionBrowserImpl::callScenarioScoresMethod(const char *name, int numArg, nlassert(name); { CLuaStackRestorer lsr(_Lua, _Lua->getTop() + numResult); - _Lua->pushValue(LUA_GLOBALSINDEX); + _Lua->pushGlobalTable(); CLuaObject rap(*_Lua); rap = rap["ScenarioScores"]; rap.callMethodByNameNoThrow(name, numArg, numResult);