bit.lua 684 B

12345678910111213141516171819202122232425262728
  1. local ok, e
  2. ok = nil
  3. if not ok then
  4. ok, e = pcall(require, "bit") -- the LuaJIT one ?
  5. end
  6. if not ok then
  7. ok, e = pcall(require, "bit32") -- Lua 5.2
  8. end
  9. if not ok then
  10. ok, e = pcall(require, "bit.numberlua") -- for Lua 5.1, https://github.com/tst2005/lua-bit-numberlua/
  11. end
  12. if not ok then
  13. ok, e = pcall(require, "lockbox.util.bit53")
  14. end
  15. if not ok then
  16. error("no bitwise support found", 2)
  17. end
  18. assert(type(e) == "table", "invalid bit module")
  19. -- Workaround to support Lua 5.2 bit32 API with the LuaJIT bit one
  20. if e.rol and not e.lrotate then
  21. e.lrotate = e.rol
  22. end
  23. if e.ror and not e.rrotate then
  24. e.rrotate = e.ror
  25. end
  26. return e