2 ms·
If you want to allow unknown types to do your multiplying, you can write __mul like so: [...] elseif getmetatable(right).__mul and getmetatable(right)
by scythe 6y ago
If you want to allow unknown types to do your multiplying, you can write __mul like so:
[...]
elseif getmetatable(right).__mul and getmetatable(right) ~= complex then
return getmetatable(right).__mul(left, right)
[...]
Of course this requires a little forward thinking, but it doesn't require you to know what other metatables (classes) you'll be compatible with. It's not as clean as multiple dispatch, though.