I'm trying to run the following in Lua 5.3
function new_t()
local self = {}
setmetatable(self, {
__add = function(lhs,rhs)
print('ok so',lhs,'+',rhs)
end
})
return self
end
local t1 = new_t()
local t2 = new_t()
t1 + t2
I get an error saying syntax error near '+'. However if I change the last line to x = t1 + t2, it runs and prints without error.
Is it possible to use a binary operator without using the resulting value? Why doesn't Lua let me do t1 + t2 or even 1 + 2 by itself?
__add, or is that some kind of temporary testing thing?t1:add(t2), I want to tryt1 + t2.print( t1 + t2 )ort1 = t1 + t2