Skip to content

Commit 3fbba9f

Browse files
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
1 parent 26a7b69 commit 3fbba9f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

script/vm/operator.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ vm.binarySwitch = util.switch()
261261
})
262262
else
263263
local node = vm.runOperator(binaryMap[op], source[1], source[2])
264+
if not node then
265+
node = vm.runOperator(binaryMap[op], source[2], source[1])
266+
end
264267
if node then
265268
vm.setNode(source, node)
266269
end
@@ -300,6 +303,9 @@ vm.binarySwitch = util.switch()
300303
})
301304
else
302305
local node = vm.runOperator(binaryMap[op], source[1], source[2])
306+
if not node then
307+
node = vm.runOperator(binaryMap[op], source[2], source[1])
308+
end
303309
if node then
304310
vm.setNode(source, node)
305311
return
@@ -396,6 +402,9 @@ vm.binarySwitch = util.switch()
396402
return
397403
end
398404
local node = vm.runOperator(binaryMap[source.op.type], source[1], source[2])
405+
if not node then
406+
node = vm.runOperator(binaryMap[source.op.type], source[2], source[1])
407+
end
399408
if node then
400409
vm.setNode(source, node)
401410
end

0 commit comments

Comments
 (0)