2
0

_hx_bit.lua 913 B

123456789101112131415161718192021
  1. local hasBit32, bit32 = pcall(require, 'bit32')
  2. if hasBit32 then --if we are on Lua 5.1, bit32 will be the default.
  3. _hx_bit_raw = bit32
  4. _hx_bit = setmetatable({}, { __index = _hx_bit_raw })
  5. -- lua 5.2 weirdness
  6. _hx_bit.bnot = function(...) return _hx_bit_clamp(_hx_bit_raw.bnot(...)) end
  7. _hx_bit.bxor = function(...) return _hx_bit_clamp(_hx_bit_raw.bxor(...)) end
  8. else
  9. --If we do not have bit32, fallback to 'bit'
  10. local hasBit, bit = pcall(require, 'bit')
  11. if not hasBit then
  12. error("Failed to load bit or bit32")
  13. end
  14. _hx_bit_raw = bit
  15. _hx_bit = setmetatable({}, { __index = _hx_bit_raw })
  16. end
  17. -- see https://github.com/HaxeFoundation/haxe/issues/8849
  18. _hx_bit.bor = function(...) return _hx_bit_clamp(_hx_bit_raw.bor(...)) end
  19. _hx_bit.band = function(...) return _hx_bit_clamp(_hx_bit_raw.band(...)) end
  20. _hx_bit.arshift = function(...) return _hx_bit_clamp(_hx_bit_raw.arshift(...)) end