An example:
1
2
2
t = { age = 42, height = 102 }
m = { __add = function (tbl, n) return t.age + n end }
Would be appreciated
Scripts
Function in table
Function in table
1

t = { age = 42, height = 102 }
m = { __add = function (tbl, n) return t.age + n end }
t = {
age = 42,
height = 102
}
m = {
--called when we use the '+' operator on the given 'tbl'
__add = function (tbl, n)
return tbl.age + n
end
}
--Make it so the table 't' gets the metatable 'm'
setmetatable(t, m)
print(t + 3) --would be t.age + 3, so we expect 42 +3 aka 45
TrialAndError explained, you can create your own __tostring to create a different text when someone does tostring(yourTable)with your table etc.
1
