File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -7,15 +7,19 @@ The bit operations are only done
7
7
This means we can ignore the differences between bit libraries.
8
8
]]
9
9
10
- -- Lua 5.3 has built-in bit operators, wrap them in a function.
11
- if _VERSION == " Lua 5.3" then
10
+ -- Lua 5.1 didn't have `load` or bitwise operators, just let it fall through.
11
+ if _VERSION ~= " Lua 5.1" then
12
+ -- Lua 5.3+ has built-in bit operators, wrap them in a function.
12
13
-- Use debug.getinfo to get correct file+line numbers for loaded snippet
13
14
local info = debug.getinfo (1 , " Sl" )
14
- return assert (load ((" \n " ):rep (info .currentline + 1 ).. [[ return {
15
+ local has_bitwise , bitwise = pcall (load ((" \n " ):rep (info .currentline + 1 ).. [[ return {
15
16
band = function(a, b) return a & b end;
16
17
bor = function(a, b) return a | b end;
17
18
bxor = function(a, b) return a ~ b end;
18
- }]] , info .source ))()
19
+ }]] , info .source ))
20
+ if has_bitwise then
21
+ return bitwise
22
+ end
19
23
end
20
24
21
25
-- The "bit" library that comes with luajit
You can’t perform that action at this time.
0 commit comments