Matt Stancliff d071e5feab 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.
2014-11-14 17:18:43 +01:00
..
2012-04-13 17:52:33 -07:00
2014-10-06 10:07:01 +02:00
2014-08-26 10:41:02 +02:00
2014-10-29 14:26:48 +01:00
2014-10-29 14:26:48 +01:00
2014-10-06 10:07:01 +02:00
2013-01-19 10:59:44 +01:00
2014-10-06 10:07:02 +02:00
2014-08-26 10:41:01 +02:00
2014-04-22 16:14:59 +02:00
2014-08-26 10:41:01 +02:00
2014-11-12 11:17:44 +01:00
2014-08-26 10:41:02 +02:00
2014-07-18 12:20:55 +02:00
2014-08-26 10:41:02 +02:00
2014-08-26 10:41:02 +02:00
2014-08-26 10:41:02 +02:00
2014-08-26 10:41:02 +02:00
2014-11-12 09:51:29 +01:00
2014-11-14 17:18:43 +01:00
2014-10-06 10:07:01 +02:00
2014-08-26 10:41:02 +02:00
2014-10-06 10:07:01 +02:00
2013-01-19 10:59:44 +01:00
2014-07-18 12:20:55 +02:00
2014-07-18 12:20:55 +02:00
2014-08-26 10:41:01 +02:00
2014-10-06 10:07:01 +02:00
2013-07-02 12:08:07 +02:00
2011-07-06 15:22:00 +02:00
2013-09-03 15:15:51 +02:00