Skip to content

Commit 402777f

Browse files
committed
http/bit: refactor to try bitwise operators in 5.3+
Rather than only attempt in Lua 5.3. This improves Lua 5.4 compatibility.
1 parent 20f36e5 commit 402777f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

http/bit.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ The bit operations are only done
77
This means we can ignore the differences between bit libraries.
88
]]
99

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.
1213
-- Use debug.getinfo to get correct file+line numbers for loaded snippet
1314
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 {
1516
band = function(a, b) return a & b end;
1617
bor = function(a, b) return a | b end;
1718
bxor = function(a, b) return a ~ b end;
18-
}]], info.source))()
19+
}]], info.source))
20+
if has_bitwise then
21+
return bitwise
22+
end
1923
end
2024

2125
-- The "bit" library that comes with luajit

0 commit comments

Comments
 (0)