At some point in the untouchable program, a comparison is made between the two Lua values:
return a==b;
I need to turn this == into >= , so I came to the following hack:
a = { value=5 } b = { value=2 } mt = { __eq = function (op1, op2) return op1.value >= op2.value end } setmetatable(a, mt) setmetatable(b, mt) print(a == b)
And this gives the expected result ( true ). Now the problem is that a and b are in different contexts, so I cannot do this:
setmetatable(a, mt) setmetatable(b, mt)
Instead, I can do:
mtA = { __eq = function (op1, op2) return op1.value >= op2.value end } setmetatable(a, mtA) mtB = { __eq = function (op1, op2) return op1.value >= op2.value end } setmetatable(b, mtB)
But then a and b are of different types, and the == operator returns false , without even reaching the __eq overload.
Any idea on how to achieve what I need?
source share