Metatable Events |
|
Lua 5.3 introduced the ability to use true integers, and with it bitwise operations. These operations are invoked similar to the addition operation, except that Lua will try a metamethod if any operand is neither an integer nor a value coercible to an integer.
t1a = {} t1b = {} t2 = {} mt1 = { __eq = function( o1, o2 ) return 'whee' end } mt2 = { __eq = function( o1, o2 ) return 'whee' end } setmetatable( t1a, mt1 ) setmetatable( t1b, mt1 ) setmetatable( t2, mt2 ) print( t1a == t1b ) --> true print( t1a == t2 ) --> false
t1
and t2
are referencing the same table, the __eq
method is not invoked for t1 == t2
:
function foo (o1, o2) print( '__eq call' ) return false end t1 = {} setmetatable( t1, {__eq = foo} ) t2 = t1 print( t1 == t2 ) --> true -- string '__eq call' not printed (and comparison result is true, not like the return value of foo(...)), so no foo(...) call here t3 = {} setmetatable( t3, {__eq = foo} ) if t1 == t3 then end --> __eq call -- foo(...) was called
a > b == b < a
a >= b == b <= a