m = {}
m.__add = function(...) print("add","+",...) end
m.__sub = function(...) print("sub","-",...) end
m.__mul = function(...) print("mul","*",...) end
m.__div = function(...) print("div","/",...) end
m.__mod = function(...) print("mod","%",...) end
m.__pow = function(...) print("pow","^",...) end
m.__unm = function(...) print("unm","-",...) end
m.__concat = function(...) print("concat","..",...) end
m.__len = function(...) print("len","#",...) end --only func on obj is not string or table
m.__eq = function(...) print("eq","==",...) end
m.__lt = function(...) print("lt","<",...) end
m.__le = function(...) print("le","<=",...) end
m.__index = function(...) print("index",...) end
m.__newindex = function(...) print("newindex",...) end
m.__call = function(...) print("call","()",...) end
o = {}
o2 = {}
setmetatable(o,m)
setmetatable(o2,m)
t=o+1
t=o-2
t=o*3
t=o/4
t=o%5
t=o^6
t=-o
t=o..8
t=#o --cause o is table,__len not be used
t=(o==o2) --must same type and can not be number or string
t=(o<o2)
t=(o<=o2)
t=o[9]
o[10] = 10
t=o(11)
m.__add = function(...) print("add","+",...) end
m.__sub = function(...) print("sub","-",...) end
m.__mul = function(...) print("mul","*",...) end
m.__div = function(...) print("div","/",...) end
m.__mod = function(...) print("mod","%",...) end
m.__pow = function(...) print("pow","^",...) end
m.__unm = function(...) print("unm","-",...) end
m.__concat = function(...) print("concat","..",...) end
m.__len = function(...) print("len","#",...) end --only func on obj is not string or table
m.__eq = function(...) print("eq","==",...) end
m.__lt = function(...) print("lt","<",...) end
m.__le = function(...) print("le","<=",...) end
m.__index = function(...) print("index",...) end
m.__newindex = function(...) print("newindex",...) end
m.__call = function(...) print("call","()",...) end
o = {}
o2 = {}
setmetatable(o,m)
setmetatable(o2,m)
t=o+1
t=o-2
t=o*3
t=o/4
t=o%5
t=o^6
t=-o
t=o..8
t=#o --cause o is table,__len not be used
t=(o==o2) --must same type and can not be number or string
t=(o<o2)
t=(o<=o2)
t=o[9]
o[10] = 10
t=o(11)