diff options
Diffstat (limited to 'lbitlib.c')
-rw-r--r-- | lbitlib.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbitlib.c,v 1.25 2014/03/20 19:22:16 roberto Exp roberto $ | 2 | ** $Id: lbitlib.c,v 1.26 2014/05/15 19:28:34 roberto Exp roberto $ |
3 | ** Standard library for bitwise operations | 3 | ** Standard library for bitwise operations |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -89,7 +89,7 @@ static int b_not (lua_State *L) { | |||
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
92 | static int b_shift (lua_State *L, lua_Unsigned r, int i) { | 92 | static int b_shift (lua_State *L, lua_Unsigned r, lua_Integer i) { |
93 | if (i < 0) { /* shift right? */ | 93 | if (i < 0) { /* shift right? */ |
94 | i = -i; | 94 | i = -i; |
95 | r = trim(r); | 95 | r = trim(r); |
@@ -107,18 +107,18 @@ static int b_shift (lua_State *L, lua_Unsigned r, int i) { | |||
107 | 107 | ||
108 | 108 | ||
109 | static int b_lshift (lua_State *L) { | 109 | static int b_lshift (lua_State *L) { |
110 | return b_shift(L, luaL_checkunsigned(L, 1), luaL_checkint(L, 2)); | 110 | return b_shift(L, luaL_checkunsigned(L, 1), luaL_checkinteger(L, 2)); |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | static int b_rshift (lua_State *L) { | 114 | static int b_rshift (lua_State *L) { |
115 | return b_shift(L, luaL_checkunsigned(L, 1), -luaL_checkint(L, 2)); | 115 | return b_shift(L, luaL_checkunsigned(L, 1), -luaL_checkinteger(L, 2)); |
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | static int b_arshift (lua_State *L) { | 119 | static int b_arshift (lua_State *L) { |
120 | lua_Unsigned r = luaL_checkunsigned(L, 1); | 120 | lua_Unsigned r = luaL_checkunsigned(L, 1); |
121 | int i = luaL_checkint(L, 2); | 121 | lua_Integer i = luaL_checkinteger(L, 2); |
122 | if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1)))) | 122 | if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1)))) |
123 | return b_shift(L, r, -i); | 123 | return b_shift(L, r, -i); |
124 | else { /* arithmetic shift for 'negative' number */ | 124 | else { /* arithmetic shift for 'negative' number */ |
@@ -131,9 +131,9 @@ static int b_arshift (lua_State *L) { | |||
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | static int b_rot (lua_State *L, int i) { | 134 | static int b_rot (lua_State *L, lua_Integer d) { |
135 | lua_Unsigned r = luaL_checkunsigned(L, 1); | 135 | lua_Unsigned r = luaL_checkunsigned(L, 1); |
136 | i &= (LUA_NBITS - 1); /* i = i % NBITS */ | 136 | int i = d & (LUA_NBITS - 1); /* i = d % NBITS */ |
137 | r = trim(r); | 137 | r = trim(r); |
138 | if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */ | 138 | if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */ |
139 | r = (r << i) | (r >> (LUA_NBITS - i)); | 139 | r = (r << i) | (r >> (LUA_NBITS - i)); |
@@ -143,12 +143,12 @@ static int b_rot (lua_State *L, int i) { | |||
143 | 143 | ||
144 | 144 | ||
145 | static int b_lrot (lua_State *L) { | 145 | static int b_lrot (lua_State *L) { |
146 | return b_rot(L, luaL_checkint(L, 2)); | 146 | return b_rot(L, luaL_checkinteger(L, 2)); |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
150 | static int b_rrot (lua_State *L) { | 150 | static int b_rrot (lua_State *L) { |
151 | return b_rot(L, -luaL_checkint(L, 2)); | 151 | return b_rot(L, -luaL_checkinteger(L, 2)); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
@@ -159,14 +159,14 @@ static int b_rrot (lua_State *L) { | |||
159 | ** 'width' being used uninitialized.) | 159 | ** 'width' being used uninitialized.) |
160 | */ | 160 | */ |
161 | static int fieldargs (lua_State *L, int farg, int *width) { | 161 | static int fieldargs (lua_State *L, int farg, int *width) { |
162 | int f = luaL_checkint(L, farg); | 162 | lua_Integer f = luaL_checkinteger(L, farg); |
163 | int w = luaL_optint(L, farg + 1, 1); | 163 | lua_Integer w = luaL_optinteger(L, farg + 1, 1); |
164 | luaL_argcheck(L, 0 <= f, farg, "field cannot be negative"); | 164 | luaL_argcheck(L, 0 <= f, farg, "field cannot be negative"); |
165 | luaL_argcheck(L, 0 < w, farg + 1, "width must be positive"); | 165 | luaL_argcheck(L, 0 < w, farg + 1, "width must be positive"); |
166 | if (f + w > LUA_NBITS) | 166 | if (f + w > LUA_NBITS) |
167 | luaL_error(L, "trying to access non-existent bits"); | 167 | luaL_error(L, "trying to access non-existent bits"); |
168 | *width = w; | 168 | *width = (int)w; |
169 | return f; | 169 | return (int)f; |
170 | } | 170 | } |
171 | 171 | ||
172 | 172 | ||