sproto support all integer representation

This commit is contained in:
Cloud Wu
2015-11-02 19:50:51 +08:00
parent 31340cf346
commit d83fc0c00f

View File

@@ -41,8 +41,18 @@ LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
#if LUA_VERSION_NUM < 503 #if LUA_VERSION_NUM < 503
// lua_isinteger is lua 5.3 api #if LUA_VERSION_NUM < 502
#define lua_isinteger lua_isnumber 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 // work around , use push & lua_gettable may be better
#define lua_geti lua_rawgeti #define lua_geti lua_rawgeti
@@ -156,11 +166,11 @@ encode(const struct sproto_arg *args) {
case SPROTO_TINTEGER: { case SPROTO_TINTEGER: {
lua_Integer v; lua_Integer v;
lua_Integer vh; 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)", return luaL_error(L, ".%s[%d] is not an integer (Is a %s)",
args->tagname, args->index, lua_typename(L, lua_type(L, -1))); args->tagname, args->index, lua_typename(L, lua_type(L, -1)));
} else {
v = lua_tointeger(L, -1);
} }
lua_pop(L,1); lua_pop(L,1);
// notice: in lua 5.2, lua_Integer maybe 52bit // notice: in lua 5.2, lua_Integer maybe 52bit