github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/runtime/lua/comp.lua (about) 1 print(1 == 2, 3.2 == 3.2, 3.2 == 2, {} == 1, {} == {}) 2 --> =false true false false false 3 4 print(1 < 2, 3.5 < -1, 2 < 1e10, 1e5 < 1e6, "xyz" < "xyza") 5 --> =true false true true true 6 7 print(1 <= 2, 3.5 <= -1, 2 <= 1e10, 1e5 <= 1e6, "xyz" <= "xyza") 8 --> =true false true true true 9 10 print(pcall(function() return {} <= {} end)) 11 --> ~^false\t 12 13 print(pcall(function() return {} < {} end)) 14 --> ~^false\t 15 16 local t = {} 17 local meta = {__lt=function(x, y) return not not y end} 18 setmetatable(t, meta) 19 print(t < true) 20 --> =true 21 22 -- Since Lua 5.4 the __le metamethod is no longer inferred from __lt if __le is 23 -- not implemented 24 print(pcall(function() return t <= false end)) 25 --> ~false\t.*attempt to compare a table value with a boolean value 26 27 meta.__le = meta.__lt 28 print(t <= false) 29 --> =false 30 31 do 32 local ud1 = testudata("foo") 33 local ud2 = testudata("bar") 34 35 print(ud1 == ud1) 36 --> =true 37 print(ud1 == ud2) 38 --> =false 39 40 local meta1 = {__eq=function(x, y) return true end} 41 local meta2 = {__eq=function(x, y) return false end} 42 debug.setmetatable(ud1, meta1) 43 debug.setmetatable(ud2, meta2) 44 45 print(ud1 == ud2) 46 --> =true 47 print(ud2 == ud1) 48 --> =false 49 --> =**release bar** 50 --> =**release foo** 51 end