summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatt Stancliff <matt@genges.com>2014-04-04 11:34:36 -0400
committerMatt Stancliff <matt@genges.com>2014-10-09 11:51:30 -0400
commit3fecb96122e35cb0c5809699c26eb093efda19e8 (patch)
tree186c4d9f92bdf0d0ae8d2f408fb7fb1d03cac494 /src
parent5ba47b50ae6ea5e0ed56598d0ef33dc43c6a7abf (diff)
downloadredis-3fecb96122e35cb0c5809699c26eb093efda19e8.tar.gz
Lua: Add bitop
A few people have written custom C commands because bit manipulation isn't exposed through Lua. Let's give them Mike Pall's bitop. This adds bitop 1.0.2 (2012-05-08) from http://bitop.luajit.org/ bitop is imported as "bit" into the global namespace. New Lua commands: bit.tobit, bit.tohex, bit.bnot, bit.band, bit.bor, bit.bxor, bit.lshift, bit.rshift, bit.arshift, bit.rol, bit.ror, bit.bswap Verification of working (the asserts would abort on error, so (nil) is correct): 127.0.0.1:6379> eval "assert(bit.tobit(1) == 1); assert(bit.band(1) == 1); assert(bit.bxor(1,2) == 3); assert(bit.bor(1,2,4,8,16,32,64,128) == 255)" 0 (nil) 127.0.0.1:6379> eval 'assert(0x7fffffff == 2147483647, "broken hex literals"); assert(0xffffffff == -1 or 0xffffffff == 2^32-1, "broken hex literals"); assert(tostring(-1) == "-1", "broken tostring()"); assert(tostring(0xffffffff) == "-1" or tostring(0xffffffff) == "4294967295", "broken tostring()")' 0 (nil) Tests also integrated into the scripting tests and can be run with: ./runtest --single unit/scripting Tests are excerpted from `bittest.lua` included in the bitop distribution.
Diffstat (limited to 'src')
-rw-r--r--src/scripting.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/scripting.c b/src/scripting.c
index 77a98abdc..39bfe5fa7 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -537,6 +537,7 @@ void luaLoadLib(lua_State *lua, const char *libname, lua_CFunction luafunc) {
LUALIB_API int (luaopen_cjson) (lua_State *L);
LUALIB_API int (luaopen_struct) (lua_State *L);
LUALIB_API int (luaopen_cmsgpack) (lua_State *L);
+LUALIB_API int (luaopen_bit) (lua_State *L);
void luaLoadLibraries(lua_State *lua) {
luaLoadLib(lua, "", luaopen_base);
@@ -547,6 +548,7 @@ void luaLoadLibraries(lua_State *lua) {
luaLoadLib(lua, "cjson", luaopen_cjson);
luaLoadLib(lua, "struct", luaopen_struct);
luaLoadLib(lua, "cmsgpack", luaopen_cmsgpack);
+ luaLoadLib(lua, "bit", luaopen_bit);
#if 0 /* Stuff that we don't load currently, for sandboxing concerns. */
luaLoadLib(lua, LUA_LOADLIBNAME, luaopen_package);