Skip to content
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

[feature request] Compile bitwise operators into Lua BitOp functions calls #151

Open
SkyyySi opened this issue Oct 8, 2023 · 2 comments

Comments

@SkyyySi
Copy link

SkyyySi commented Oct 8, 2023

For Lua versions below 5.3, bitwise operators aren't supported. However, their behavior can be substituted using the Lua BitOp library. This library is also included by default with LuaJIT. My suggestion would be to add a boolean argument to the compiler, perhaps a --use-bit-lib (which is what Fennel also uses). In practice, it could compile the code:

bit_or = (x, y) ->
    x | y

into this:

_bitop_0 = require("bit")
local bit_or
bit_or = function(x, y)
    return _bitop_0.bor(x, y)
end
@SkyyySi SkyyySi changed the title [feature request] Compile bitwise operators into luabitop functions calls [feature request] Compile bitwise operators into Lua BitOp functions calls Oct 8, 2023
@SkyyySi
Copy link
Author

SkyyySi commented Oct 8, 2023

Additionally, the floor division operator x // y could be compiled to math.floor(x / y).

@SkyyySi
Copy link
Author

SkyyySi commented Oct 20, 2023

An alternative might be to allow choosing the bit library, as Lua 5.2 includes the "bit32" library by default.

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

No branches or pull requests

1 participant