Add lua_isinteger for lua 5.1 and 5.2

pull/188/head
Hleb Valoshka 2018-12-31 18:04:58 +03:00
parent bca39dc424
commit f56c3a104b
3 changed files with 17 additions and 6 deletions

View File

@ -110,6 +110,19 @@ const char* MouseDownHandler = "mousedown";
const char* MouseUpHandler = "mouseup";
#if LUA_VER < 0x050300
int lua_isinteger(lua_State *L, int index)
{
if (lua_type(L, index) == LUA_TNUMBER)
{
if (lua_tonumber(L, index) == lua_tointeger(L, index))
return 1;
}
return 0;
}
#endif
// Initialize various maps from named keywords to numeric flags used within celestia:
void CelxLua::initRenderFlagMap()
{

View File

@ -32,6 +32,10 @@ extern "C" {
#include <celutil/timer.h>
#include <celengine/observer.h>
#if LUA_VER < 0x050300
int lua_isinteger(lua_State *L, int index);
#endif
class CelestiaCore;
class View;

View File

@ -110,13 +110,11 @@ public:
lua_pushboolean(m_lua, a);
return 1;
}
#if LUA_VER >= 0x050300
int push(int a)
{
lua_pushinteger(m_lua, a);
return 1;
}
#endif
int push(float a)
{
lua_pushnumber(m_lua, a);
@ -213,9 +211,7 @@ public:
/**** type check methods ****/
bool isType(int index, int type) const;
#if LUA_VER >= 0x050300
bool isInteger(int n = 0) const { return lua_isinteger(m_lua, n); }
#endif
bool isNumber(int n = 0) const { return lua_isnumber(m_lua, n); }
bool isBoolean(int n = 0) const { return lua_isboolean(m_lua, n); }
bool isString(int n = 0) const { return lua_isstring(m_lua, n); }
@ -224,9 +220,7 @@ public:
/**** get methods ****/
#if LUA_VER >= 0x050300
int getInt(int n = 0) const { return lua_tointeger(m_lua, n); }
#endif
double getNumber(int n = 0) const { return lua_tonumber(m_lua, n); }
bool getBoolean(int n = 0) const { return lua_toboolean(m_lua, n); }
const char *getString(int n = 0) const { return lua_tostring(m_lua, n); }