Skip to content

Commit

Permalink
Fix passing integers to dostring and remotedostring
Browse files Browse the repository at this point in the history
When copying arguments for dostring and remotedostring
between two Lua states, under Lua it is important to keep integers
integers. Previously 'lua_pushnumber(state1, lua_tonumber(state2, idx))'
was used which turned all numbers into floats. Fix by checking if a number
is an integer using 'lua_isinteger' first.
  • Loading branch information
mpeterv committed Jul 5, 2016
1 parent 9e5b9f6 commit 9ee8669
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/rings.c
Expand Up @@ -27,6 +27,10 @@
# define lua_setfenv(L,i) lua_setupvalue(L, i, 1)
#endif

#if LUA_VERSION_NUM < 503
# define lua_isinteger(L, i) ((void) (L), (void) (i), 0)
#endif

typedef struct {
lua_State *L;
} state_data;
Expand Down Expand Up @@ -62,7 +66,11 @@ static void copy_values (lua_State *dst, lua_State *src, int i, int top) {
for (; i <= top; i++) {
switch (lua_type (src, i)) {
case LUA_TNUMBER:
lua_pushnumber (dst, lua_tonumber (src, i));
if (lua_isinteger(src, i)) {
lua_pushinteger(dst, lua_tointeger(src, i));
} else {
lua_pushnumber(dst, lua_tonumber(src, i));
}
break;
case LUA_TBOOLEAN:
lua_pushboolean (dst, lua_toboolean (src, i));
Expand Down

0 comments on commit 9ee8669

Please sign in to comment.