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

feat: flip binary operator check if failed (#2777) #2779

Merged
merged 3 commits into from
Aug 6, 2024

Conversation

SeanTheBuilder1
Copy link
Contributor

@SeanTheBuilder1 SeanTheBuilder1 commented Aug 3, 2024

#2777
if vm.runOperator fails try again with flipped arguments
this emulates how lua checks the binary metaevents in which
if there is no corresponding binary metaevent for the left
operand it checks the right operand instead. This also works
when both operands are tables.

example case:

---@class Vector3
---@operator add(number): Vector3
Vector3 = {}

---@type number
local x
local a = x + Vector3
-- type of a is now Vector3

This change affects:

  • __add
  • __sub
  • __mul
  • __div
  • __idiv
  • __mod
  • __pow
  • __concat
  • __band
  • __bor
  • __bxor
  • __shl
  • __shr

Credit to tomlau10 for preliminary code

@CppCXY CppCXY added the enhancement New feature or request label Aug 3, 2024
if vm.runOperator fails try again with flipped arguments
this emulates how lua checks the binary metaevents in which
if there is no corresponding binary metaevent for the left
operand it checks the right operand instead. This also works
when both operands are tables.

This change affects:
- __add
- __sub
- __mul
- __div
- __idiv
- __mod
- __pow
- __concat
- __band
- __bor
- __bxor
- __shl
- __shr
@sumneko sumneko force-pushed the binary-ops-symmetry branch from bc46110 to 8635fef Compare August 6, 2024 13:13
@sumneko sumneko merged commit e0a4869 into LuaLS:master Aug 6, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants