-
Notifications
You must be signed in to change notification settings - Fork 0
Use lua native mods for bit rotation #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
| 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, | ||
| } |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
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.
No description provided.