bit53.lua 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. -- error("no bitwise support found", 2)
  14. -- end
  15. -- assert(type(e) == "table", "invalid bit module")
  16. -- -- Workaround to support Lua 5.2 bit32 API with the LuaJIT bit one
  17. -- if e.rol and not e.lrotate then
  18. -- e.lrotate = e.rol
  19. -- end
  20. -- if e.ror and not e.rrotate then
  21. -- e.rrotate = e.ror
  22. -- end
  23. -- return e
  24. local Bit = {};
  25. Bit.bxor = function (p1,p2)
  26. return p1 ~ p2
  27. end
  28. Bit.band = function (p1,p2)
  29. return p1 & p2
  30. end
  31. Bit.bor = function (p1,p2)
  32. return p1 | p2
  33. end
  34. Bit.bnot = function (p1)
  35. return ~p1
  36. end
  37. Bit.lshift = function (p1,p2)
  38. return p1 << p2
  39. end
  40. Bit.rshift = function (p1,p2)
  41. return p1 >> p2
  42. end
  43. return Bit