Okay, so I decided to try out Lua 5.2 today. I was really interested in the new binary library called bit. Some of the functions run lightning fast compared to what I can make on my own, mainly because they've been implemented on the C side of开发者_如何学JAVA Lua. Take the binary XOR function, it runs 34 times faster than my Lua implementation of XOR.
So, my dilemma is: I think there's a bug in the binary functions already
print(bit.bnot(0)) --> 4294967295
That's correct, because 4294967295 is 11111111 11111111 11111111 11111111 in binary
However,
print(bit.band(4294967295, 65535)) --> 0
Which is wrong, or atleast I think it should be. 65535 in binary is 11111111 11111111. When I use bit.band in the afore mentioned situation shouldn't 65535 be returned ?
I'm using Lua 5.2.0-work2 precompiled binaries from here
I have not looked at the Lua 5.2 releases at all, but if your primary interest is in binary operations, there is a BitOp module for Lua 5.1 here which is source compatible with the native implementations provided by LuaJit.
精彩评论