19#if defined(LUA_COMPAT_BITLIB)
22#define pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
23#define checkunsigned(L,i) ((lua_Unsigned)luaL_checkinteger(L,i))
27#if !defined(LUA_NBITS)
37#define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1))
41#define trim(x) ((x) & ALLONES)
45#define mask(n) (~((ALLONES << 1) << ((n) - 1)))
52 for (i = 1; i <= n; i++)
53 r &= checkunsigned(L, i);
75 for (i = 1; i <= n; i++)
76 r |= checkunsigned(L, i);
77 pushunsigned(L,
trim(r));
85 for (i = 1; i <= n; i++)
86 r ^= checkunsigned(L, i);
87 pushunsigned(L,
trim(r));
94 pushunsigned(L,
trim(r));
147 pushunsigned(L,
trim(r));
174 luaL_error(L,
"trying to access non-existent bits");
184 r = (r >> f) &
mask(w);
196 r = (r & ~(m << f)) | ((v & m) << f);
230 return luaL_error(L,
"library 'bit32' has been deprecated");
LUA_API void lua_pushboolean(lua_State *L, int b)
LUA_API int lua_gettop(lua_State *L)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def)
#define luaL_argcheck(L, cond, numarg, extramsg)
#define luaL_newlib(L, l)
static int b_rrot(lua_State *L)
static int b_xor(lua_State *L)
static int b_replace(lua_State *L)
static int b_or(lua_State *L)
static int b_and(lua_State *L)
static int b_extract(lua_State *L)
static int b_shift(lua_State *L, b_uint r, int i)
static int fieldargs(lua_State *L, int farg, int *width)
static int b_rshift(lua_State *L)
static int b_not(lua_State *L)
static int b_lshift(lua_State *L)
static const luaL_Reg bitlib[]
static int b_lrot(lua_State *L)
static int b_test(lua_State *L)
static int b_arshift(lua_State *L)
static int b_rot(lua_State *L, int i)
static b_uint andaux(lua_State *L)
LUA_UNSIGNED lua_Unsigned
LUAMOD_API int luaopen_bit32(lua_State *L)