diff --git a/lualib-src/sproto/lsproto.c b/lualib-src/sproto/lsproto.c index 16eaa022..1d71d887 100644 --- a/lualib-src/sproto/lsproto.c +++ b/lualib-src/sproto/lsproto.c @@ -41,8 +41,18 @@ LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { #if LUA_VERSION_NUM < 503 -// lua_isinteger is lua 5.3 api -#define lua_isinteger lua_isnumber +#if LUA_VERSION_NUM < 502 +static lua_Integer lua_tointegerx(lua_State *L, int idx, int *isnum) { + if (lua_isnumber(L, idx)) { + if (isnum) *isnum = 1; + return lua_tointeger(L, idx); + } + else { + if (isnum) *isnum = 0; + return 0; + } +} +#endif // work around , use push & lua_gettable may be better #define lua_geti lua_rawgeti @@ -156,11 +166,11 @@ encode(const struct sproto_arg *args) { case SPROTO_TINTEGER: { lua_Integer v; lua_Integer vh; - if (!lua_isinteger(L, -1)) { + int isnum; + v = lua_tointegerx(L, -1, &isnum); + if(!isnum) { return luaL_error(L, ".%s[%d] is not an integer (Is a %s)", args->tagname, args->index, lua_typename(L, lua_type(L, -1))); - } else { - v = lua_tointeger(L, -1); } lua_pop(L,1); // notice: in lua 5.2, lua_Integer maybe 52bit