Allow reversed proxy metamethods#261
Open
kunitoki wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces support for reversed proxy functions for binary operator metamethods in LuaBridge, allowing operator overloading to work seamlessly for both
obj OP valueandvalue OP objforms (e.g.,vec * 3and3 * vec). It also enforces that reversed functions can only be registered for valid binary operator metamethods, preventing misuse. Comprehensive tests are added to cover these new capabilities and restrictions.Core Library Enhancements
is_reversed_proxy_function_vandis_const_reversed_proxy_function_vtraits inFuncTraits.hto detect reversed proxy functions, where the class type is the second argument, as needed for binary operator overloads with swapped operands.is_binary_operator_metamethodutility andreversed_overload_type_checkerto identify and correctly handle binary operator metamethods and their reversed forms inCFunctions.h[1] [2].Test Suite Additions
Vec2class with overloaded arithmetic operators to thoroughly test both normal and reversed binary operator metamethods.__add,__sub,__mul,__div) and for cases where only the reversed operator is provided.Type Trait and Arity Logic
is_const_functionlogic to correctly recognize constness for reversed proxy functions.These changes significantly improve LuaBridge's operator overloading capabilities, ensuring both correctness and ease of use for C++ classes exposed to Lua.