_hx_bit.lua 511 B

123456789101112
  1. local _hx_bit
  2. pcall(require, 'bit32') pcall(require, 'bit')
  3. local _hx_bit_raw = bit or bit32
  4. local function _hx_bit_clamp(v) return _hx_bit_raw.band(v, 2147483647 ) - _hx_bit_raw.band(v, 2147483648) end
  5. if type(jit) == 'table' then
  6. _hx_bit = setmetatable({},{__index = function(t,k) return function(...) return _hx_bit_clamp(rawget(_hx_bit_raw,k)(...)) end end})
  7. else
  8. _hx_bit = setmetatable({}, { __index = _hx_bit_raw })
  9. _hx_bit.bnot = function(...) return _hx_bit_clamp(_hx_bit_raw.bnot(...)) end
  10. end