zerkman / zzlib

zip/zlib-compressed file depacking library in Lua
Do What The F*ck You Want To Public License
87 stars 21 forks source link

Lua 5.3 - no bit32 #4

Closed mikeyyuen closed 4 years ago

mikeyyuen commented 5 years ago

It looks like Lua 5.3 deprecates bit32 in favour of integer bitwise operators in 64 bits (unless compiled in compatibility mode). I took a quick look at doing something like

local bit = {
  band = function (a, b) { return a & b }
  ... etc ...
}

It looks like integer overflow might be handled differently (due to 64 / 32 bits) so I wasn't sure if that was safe, or if it might make this library faster to use all 64 bits, any thoughts on a good way to handle platforms without bit32?

zerkman commented 5 years ago

You are right. Up to now I had mostly been using LuaJIT and Debian’s build of Lua 5.3, which still has bit32 built in. I am not sure there is a clean way of having a portable implementation which can either make use of the Lua 5.3 bitwise operators or use the bit/bit32 libraries on other versions of Lua. Mostly because the bitwise operators lead to syntax errors where not available.

In the meantime I have just created a lua5.3 branch with a quick fix so that it works on Lua 5.3 using the bitwise operators.

mikeyyuen commented 5 years ago

Thanks for the branch, yes thats a good point backwards compatibility would require conditionally loading code, which is probably messy.

zerkman commented 4 years ago

I Merged the two versions of the code into master branch. Proper selection of the implementation is done at run time.