aboutsummaryrefslogtreecommitdiff
path: root/lbitlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbitlib.c')
-rw-r--r--lbitlib.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/lbitlib.c b/lbitlib.c
index 4786c0d..db2652a 100644
--- a/lbitlib.c
+++ b/lbitlib.c
@@ -19,8 +19,18 @@
19#if defined(LUA_COMPAT_BITLIB) /* { */ 19#if defined(LUA_COMPAT_BITLIB) /* { */
20 20
21 21
22#define pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n)) 22#define pushunsigned(L,n) (sizeof(lua_Integer) > 4 ? lua_pushinteger(L, (lua_Integer)(n)) : lua_pushnumber(L, (lua_Number)(n)))
23#define checkunsigned(L,i) ((lua_Unsigned)luaL_checkinteger(L,i)) 23static lua_Unsigned checkunsigned(lua_State *L, int i) {
24 if (sizeof(lua_Integer) > 4)
25 return (lua_Unsigned)luaL_checkinteger(L, i);
26 else {
27 lua_Number d = luaL_checknumber(L, i);
28 if (d < 0)
29 d = (d + 1) + (~(lua_Unsigned)0);
30 luaL_argcheck(L, d >= 0 && d <= (~(lua_Unsigned)0), i, "value out of range");
31 return (lua_Unsigned)d;
32 }
33}
24 34
25 35
26/* number of bits to consider in a number */ 36/* number of bits to consider in a number */