code / nomsu

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