Skip to content

Conversation

@blueyetisoftware
Copy link
Owner

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the dynamic bit library loading system with native Lua bitwise operators to simplify the codebase and remove dependencies on external bit libraries.

Changes:

  • Removed conditional loading of bit libraries (bit, bit32, bit.numberlua) and compatibility layer
  • Implemented all bitwise operations (band, bor, bxor, bnot, lshift, rshift, lrotate, rrotate) using native Lua operators (&, |, ~, <<, >>)
  • Simplified bit rotation functions with direct implementations using native operators

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +19
return {
band = function(l, r) return l & r end,
bor = function(l, r) return l | r end,
bxor = function(l, r) return l ~ r end,
bnot = function(u) return ~u end,
lshift = function(l, r) return l << r end,
rshift = function(l, r) return l >> r end,

-- Workaround to support Lua 5.2 bit32 API with the LuaJIT bit one
if e.rol and not e.lrotate then
e.lrotate = e.rol
end
if e.ror and not e.rrotate then
e.rrotate = e.ror
end

-- Workaround to support incomplete bit operations set
if not e.ror and not e.rrotate then
local ror = function(b, n)
return e.bor(e.rshift(b, n), e.lshift(b, 32 - n))
end

e.ror = ror
e.rrotate = ror
end

if not e.rol and not e.lrotate then
local rol = function(b, n)
return e.bor(e.lshift(b, n), e.rshift(b, 32 - n))
end

e.rol = rol
e.lrotate = rol
end

return e
lrotate = function(l, r)
l = l & 0xffffffff
r = r & 0x1f
return ((l << r) & 0xffffffff) | (l >> (32 - r))
end,
rrotate = function(l, r)
l = l & 0xffffffff
r = r & 0x1f
return (l >> r) | (0xffffffff & (l << (32 - r)))
end,
}
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation uses native bitwise operators (&, |, ~, <<, >>) that were only introduced in Lua 5.3. However, the project's rockspec specifies "lua >= 5.2" and .travis.yml tests against Lua 5.2 and LuaJIT 2.0, neither of which support these operators. This change breaks backward compatibility and will cause runtime errors on Lua 5.2 and LuaJIT.

The previous implementation correctly used conditional requires to support multiple Lua versions. Either the Lua version requirement needs to be updated to >= 5.3 in the rockspec and CI configuration, or this implementation needs to be revised to maintain backward compatibility.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants