Skip to content

Commit d83fc0c

Browse files
committed
sproto support all integer representation
1 parent 31340cf commit d83fc0c

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lualib-src/sproto/lsproto.c

+15-5
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,18 @@ LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
4141

4242
#if LUA_VERSION_NUM < 503
4343

44-
// lua_isinteger is lua 5.3 api
45-
#define lua_isinteger lua_isnumber
44+
#if LUA_VERSION_NUM < 502
45+
static lua_Integer lua_tointegerx(lua_State *L, int idx, int *isnum) {
46+
if (lua_isnumber(L, idx)) {
47+
if (isnum) *isnum = 1;
48+
return lua_tointeger(L, idx);
49+
}
50+
else {
51+
if (isnum) *isnum = 0;
52+
return 0;
53+
}
54+
}
55+
#endif
4656

4757
// work around , use push & lua_gettable may be better
4858
#define lua_geti lua_rawgeti
@@ -156,11 +166,11 @@ encode(const struct sproto_arg *args) {
156166
case SPROTO_TINTEGER: {
157167
lua_Integer v;
158168
lua_Integer vh;
159-
if (!lua_isinteger(L, -1)) {
169+
int isnum;
170+
v = lua_tointegerx(L, -1, &isnum);
171+
if(!isnum) {
160172
return luaL_error(L, ".%s[%d] is not an integer (Is a %s)",
161173
args->tagname, args->index, lua_typename(L, lua_type(L, -1)));
162-
} else {
163-
v = lua_tointeger(L, -1);
164174
}
165175
lua_pop(L,1);
166176
// notice: in lua 5.2, lua_Integer maybe 52bit

0 commit comments

Comments
 (0)