aboutsummaryrefslogtreecommitdiff
path: root/bitops.lua
blob: f87be64772890e16441ccf4a10ec0f1f07429403 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
local bitlib
if jit then
  bitlib = require('bit')
elseif _VERSION == "Lua 5.2" then
  bitlib = bit32
else
  bitlib = error("no bit library for Lua 5.3+")
end
local ret
do
  local _tbl_0 = { }
  for k, v in pairs(bitlib) do
    _tbl_0[k] = v
  end
  ret = _tbl_0
end
ret.bnot = function(x)
  do
    local mt = getmetatable(x)
    if mt then
      if mt.__bnot then
        return mt.__bnot(x)
      end
    end
  end
  return bitlib.bnot(x)
end
ret.band = function(x, y)
  do
    local mt_x = getmetatable(x)
    if mt_x then
      if mt_x.__band then
        return mt_x.__band(x, y)
      end
    end
  end
  do
    local mt_y = getmetatable(x)
    if mt_y then
      if mt_y.__band then
        return mt_y.__band(x, y)
      end
    end
  end
  return bitlib.band(x, y)
end
ret.bor = function(x, y)
  do
    local mt_x = getmetatable(x)
    if mt_x then
      if mt_x.__bor then
        return mt_x.__bor(x, y)
      end
    end
  end
  do
    local mt_y = getmetatable(x)
    if mt_y then
      if mt_y.__bor then
        return mt_y.__bor(x, y)
      end
    end
  end
  return bitlib.bor(x, y)
end
ret.bxor = function(x, y)
  do
    local mt_x = getmetatable(x)
    if mt_x then
      if mt_x.__bxor then
        return mt_x.__bxor(x, y)
      end
    end
  end
  do
    local mt_y = getmetatable(x)
    if mt_y then
      if mt_y.__bxor then
        return mt_y.__bxor(x, y)
      end
    end
  end
  return bitlib.bxor(x, y)
end
ret.lshift = function(x, y)
  do
    local mt_x = getmetatable(x)
    if mt_x then
      if mt_x.__shl then
        return mt_x.__shl(x, y)
      end
    end
  end
  do
    local mt_y = getmetatable(x)
    if mt_y then
      if mt_y.__shl then
        return mt_y.__shl(x, y)
      end
    end
  end
  return bitlib.lshift(x, y)
end
ret.rshift = function(x, y)
  do
    local mt_x = getmetatable(x)
    if mt_x then
      if mt_x.__shr then
        return mt_x.__shr(x, y)
      end
    end
  end
  do
    local mt_y = getmetatable(x)
    if mt_y then
      if mt_y.__shr then
        return mt_y.__shr(x, y)
      end
    end
  end
  return bitlib.rshift(x, y)
end
return ret