Fixes to compile Ryzom Client with lua 5.2
This commit is contained in:
parent
a06e106212
commit
5fa4beab46
9 changed files with 43 additions and 21 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -5164,7 +5164,7 @@ NLMISC_COMMAND(luaObject, "Dump the content of a lua object", "<table name> [max
|
|||
CLuaIHMRyzom::debugInfo(e.what());
|
||||
return false;
|
||||
}
|
||||
luaState->pushValue(LUA_GLOBALSINDEX);
|
||||
luaState->pushGlobalTable();
|
||||
CLuaObject env;
|
||||
env.pop(*luaState);
|
||||
uint maxDepth;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue