diff options
author | SeanTheBuilder1 <seanthebuilder52@gmail.com> | 2024-08-03 14:26:12 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2024-08-06 21:13:33 +0800 |
commit | 15c716da6c690b7b8dcb90d9eec13a449dfc0e05 (patch) | |
tree | 4d0dbd9da27152021c33d56dc897cae07c308cad | |
parent | 1dbe571cfe8b003f539f09385d7b719f7f13b381 (diff) | |
download | lua-language-server-15c716da6c690b7b8dcb90d9eec13a449dfc0e05.zip |
feat: flip binary operator check if failed
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
-rw-r--r-- | script/vm/operator.lua | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/script/vm/operator.lua b/script/vm/operator.lua index 7ce2b30d..07ce19eb 100644 --- a/script/vm/operator.lua +++ b/script/vm/operator.lua @@ -261,6 +261,9 @@ vm.binarySwitch = util.switch() }) else local node = vm.runOperator(binaryMap[op], source[1], source[2]) + if not node then + node = vm.runOperator(binaryMap[op], source[2], source[1]) + end if node then vm.setNode(source, node) end @@ -300,6 +303,9 @@ vm.binarySwitch = util.switch() }) else local node = vm.runOperator(binaryMap[op], source[1], source[2]) + if not node then + node = vm.runOperator(binaryMap[op], source[2], source[1]) + end if node then vm.setNode(source, node) return @@ -396,6 +402,9 @@ vm.binarySwitch = util.switch() return end local node = vm.runOperator(binaryMap[source.op.type], source[1], source[2]) + if not node then + node = vm.runOperator(binaryMap[source.op.type], source[2], source[1]) + end if node then vm.setNode(source, node) end |