I have overloaded multiplication operator like this in a table metatable designed to imitate a class.
function classTestTable(members)
members = members or {}
local mt = {
__metatable = members;
__index = members;
}
function mt.__mul(o1, o2)
blah. blah blah
end
return mt
end
TestTable = {}
TestTable_mt = ClassTestTable(TestTable)
function TestTable:new()
return setmetatable({targ1 = 1}, TestTable_mt )
end
TestTable t1 = TestTable:new()
t2 = 3 * t1 -- is calling mt.__mul(3, t1)
t3 = t1 * 3 -- is calling mt.__mul(t1, 3)
How do I check which argument in the function call for function mt.__mul(o1, o2) is of type TestTable?
I need to know this to implement the overloaded multiplication correctly.
You can do like Egor suggested or you could use something like this:
And create your class like so:
Then you can simply check wether
o1.is_a[TestTable]
is true.