Compile NLGUI with lua 5.2

This commit is contained in:
kaetemi 2013-06-16 02:33:04 +02:00
parent cfec0964d4
commit 7bb6775261
4 changed files with 75 additions and 4 deletions

View file

@ -217,6 +217,9 @@ 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
@ -301,7 +304,8 @@ namespace NLGUI
/** Helper : Execute a function by name. Lookup for the function is done in the table at the index 'funcTableIndex'
* the behaviour is the same than with call of pcall.
*/
int pcallByName(const char *functionName, int nargs, int nresults, int funcTableIndex = LUA_GLOBALSINDEX, int errfunc = 0);
int pcallByNameGlobal(const char *functionName, int nargs, int nresults, int errfunc = 0);
int pcallByName(const char *functionName, int nargs, int nresults, int funcTableIndex, int errfunc = 0);
// push a C closure (pop n element from the stack and associate with the function)
void pushCClosure(lua_CFunction function, int n);
@ -367,6 +371,7 @@ namespace NLGUI
CLuaState &operator=(const CLuaState &/* other */) { nlassert(0); return *this; }
void executeScriptInternal(const std::string &code, const std::string &dbgSrc, int numRet = 0);
int pcallByNameInternal(const char *functionName, int nargs, int nresults, int errfunc, int initialStackSize);
};

View file

@ -42,10 +42,16 @@ inline void CLuaState::checkIndex(int index)
//H_AUTO(Lua_CLuaState_checkIndex)
// NB : more restrictive test that in the documentation there, because
// we don't expose the check stack function
#if LUA_VERSION_NUM >= 502
nlassert( (index!=0 && abs(index) <= getTop())
|| index == LUA_REGISTRYINDEX
);
#else
nlassert( (index!=0 && abs(index) <= getTop())
|| index == LUA_REGISTRYINDEX
|| index == LUA_GLOBALSINDEX
);
#endif
}
//================================================================================
@ -75,6 +81,15 @@ inline void CLuaState::setTop(int index)
lua_settop(_State, index);
}
#if LUA_VERSION_NUM >= 502
//================================================================================
inline void CLuaState::pushGlobalTable()
{
//H_AUTO(Lua_CLuaState_pushGlobalTable)
lua_pushglobaltable(_State);
}
#endif
//================================================================================
inline void CLuaState::pushValue(int index)
{
@ -243,7 +258,11 @@ inline size_t CLuaState::strlen(int index)
{
//H_AUTO(Lua_CLuaState_strlen)
checkIndex(index);
#if LUA_VERSION_NUM >= 502
return lua_rawlen(_State, index);
#else
return lua_strlen(_State, index);
#endif
}
//================================================================================
@ -342,7 +361,11 @@ inline bool CLuaState::equal(int index1, int index2)
//H_AUTO(Lua_CLuaState_equal)
checkIndex(index1);
checkIndex(index2);
#if LUA_VERSION_NUM >= 502
return lua_compare(_State, index1, index2, LUA_OPEQ) != 0;
#else
return lua_equal(_State, index1, index2) != 0;
#endif
}
//================================================================================
@ -376,7 +399,11 @@ inline bool CLuaState::lessThan(int index1, int index2)
//H_AUTO(Lua_CLuaState_lessThan)
checkIndex(index1);
checkIndex(index2);
#if LUA_VERSION_NUM >= 502
return lua_compare(_State, index1, index2, LUA_OPLT) != 0;
#else
return lua_lessthan(_State, index1, index2) != 0;
#endif
}

View file

@ -361,7 +361,11 @@ namespace NLGUI
rd.Str = &code;
rd.Done = false;
int result = lua_load(_State, CHelper::luaChunkReaderFromString, (void *) &rd, dbgSrc.c_str());
int result = lua_load(_State, CHelper::luaChunkReaderFromString, (void *) &rd, dbgSrc.c_str()
#if LUA_VERSION_NUM >= 502
, NULL
#endif
);
if (result !=0)
{
// pop the error code
@ -569,9 +573,17 @@ namespace NLGUI
//H_AUTO(Lua_CLuaState_registerFunc)
nlassert(function);
CLuaStackChecker lsc(this);
#if LUA_VERSION_NUM >= 502
pushGlobalTable();
#endif
push(name);
push(function);
#if LUA_VERSION_NUM >= 502
setTable(-3); // -3 is the pushGlobalTable
pop(1); // pop the pushGlobalTable value (setTable popped the 2 pushes)
#else
setTable(LUA_GLOBALSINDEX);
#endif
}
@ -643,13 +655,31 @@ namespace NLGUI
}
// ***************************************************************************
int CLuaState::pcallByName(const char *functionName, int nargs, int nresults, int funcTableIndex /*=LUA_GLOBALSINDEX*/, int errfunc /*= 0*/)
int CLuaState::pcallByNameGlobal(const char *functionName, int nargs, int nresults, int errfunc /*= 0*/)
{
int initialStackSize = getTop();
nlassert(functionName);
#if LUA_VERSION_NUM >= 502
pushGlobalTable();
#else
nlassert(isTable(LUA_GLOBALSINDEX));
pushValue(LUA_GLOBALSINDEX);
#endif
return pcallByNameInternal(functionName, nargs, nresults, errfunc, initialStackSize);
}
int CLuaState::pcallByName(const char *functionName, int nargs, int nresults, int funcTableIndex, int errfunc /*= 0*/)
{
//H_AUTO(Lua_CLuaState_pcallByName)
int initialStackSize = getTop();
nlassert(functionName);
nlassert(isTable(funcTableIndex));
pushValue(funcTableIndex);
return pcallByNameInternal(functionName, nargs, nresults, errfunc, initialStackSize);
}
int CLuaState::pcallByNameInternal(const char *functionName, int nargs, int nresults, int errfunc /*= 0*/, int initialStackSize)
{
//H_AUTO(Lua_CLuaState_pcallByName)
push(functionName);
getTable(-2);
remove(-2); // get rid of the table
@ -782,7 +812,12 @@ namespace NLGUI
int CLuaState::getGCCount()
{
//H_AUTO(Lua_CLuaState_getGCCount)
#if LUA_VERSION_NUM >= 502
// deprecated
return 0;
#else
return lua_getgccount(_State);
#endif
}
//================================================================================

View file

@ -474,7 +474,11 @@ namespace NLGUI
CLuaState *luaState = table.getLuaState();
CLuaStackChecker lsc(luaState);
// get pointer to the 'next' function
#if LUA_VERSION_NUM >= 502
luaState->pushGlobalTable();
#else
luaState->pushValue(LUA_GLOBALSINDEX);
#endif
_NextFunction = CLuaObject(*luaState)["next"];
//
nlassert(luaState);