aboutsummaryrefslogtreecommitdiff

– This file defines wrapper functions around the Lua 5.2/LuaJIT bitwise operators – The wrapper functions check for the appropriate metatable functions like – “__bxor” for bit.bxor(), etc. bitlib = if jit then require(‘bit’) elseif _VERSION == “Lua 5.2” bit32 else error(“no bit library for Lua 5.3+”)

ret = {k,v for k,v in pairs(bitlib)} ret.bnot = (x)-> if mt = getmetatable(x) if mt.bnot then return mt.bnot(x) return bitlib.bnot(x) ret.band = (x,y)-> if mtx = getmetatable(x) if mtx.band then return mt_x.band(x, y) if mty = getmetatable(x) if mty.band then return mt_y.band(x, y) return bitlib.band(x, y) ret.bor = (x,y)-> if mtx = getmetatable(x) if mtx.bor then return mt_x.bor(x, y) if mty = getmetatable(x) if mty.bor then return mt_y.bor(x, y) return bitlib.bor(x, y) ret.bxor = (x,y)-> if mtx = getmetatable(x) if mtx.bxor then return mt_x.bxor(x, y) if mty = getmetatable(x) if mty.bxor then return mt_y.bxor(x, y) return bitlib.bxor(x, y) ret.lshift = (x,y)-> if mtx = getmetatable(x) if mtx.shl then return mt_x.shl(x, y) if mty = getmetatable(x) if mty.shl then return mt_y.shl(x, y) return bitlib.lshift(x, y) ret.rshift = (x,y)-> if mtx = getmetatable(x) if mtx.shr then return mt_x.shr(x, y) if mty = getmetatable(x) if mty.shr then return mt_y.shr(x, y) return bitlib.rshift(x, y)

return ret