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

Lua 5.3 bitwise operator support. #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dan-masek
Copy link

Add support for Lua 5.3's bitwise operators (and, or, xor, not, shl, shr).

XOR is a bit awkward to use, since its operator is already abused for pow.
For example:
.def("__bxor", static_cast<std::string(*)(operator_tester const&, operator_tester const&)>(&operator^))

…shr). XOR is a bit awkward to use, since its operator is already abused for pow.
@dan-masek
Copy link
Author

OK, compatibility with 5.2 and 5.1....

I suppose it's enough to make the tests conditional based on the lua version used, since having extra metatable entries shouldn't be an issue.

Do you think there's a point in making the support conditional as well?

Copy link
Owner

@Oberon00 Oberon00 left a comment

Choose a reason for hiding this comment

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

Thank you very much for the contribution! I'm not really maintaining this repository anymore, but your change looks useful and low-risk enough that I think I'm going to merge it without testing it myself 😃 If you have time to add the additional test assertions (see comment), that would be even better, otherwise tell me if you prefer to merge it as-is.

DOSTRING(L, "assert(~test == 'bitwise not operator')")
DOSTRING(L, "assert(test << test == 'left shift operator')")
DOSTRING(L, "assert(test >> test == 'right shift operator')")
#endif
Copy link
Owner

@Oberon00 Oberon00 May 15, 2021

Choose a reason for hiding this comment

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

Can you add a #else (or always-on) test that the metamethods with expected names are defined even if Lua does not interpret the names specifically?

Copy link
Author

Choose a reason for hiding this comment

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

OK, I'll have a look at it.

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