[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Metatables for numbers
- From: Greg Hill <tghill@...>
- Date: Fri, 27 Jun 2008 20:37:49 +0000 (UTC)
Petite Abeille <petite.abeille <at> gmail.com> writes:
> On Jun 27, 2008, at 8:56 PM, Tracy Hill wrote:
> > Is there a way to use the metatable __add concept on numbers( and
> > booleans)?
> You can try debug.setmetatable (object, table):
> Beware of unintended consequences as this might be too clever by half :)
It looks like debug.setmetatable is what I'm looking for.
I'm not quite sure how to use it. The following code snippet didn't work for me.
__add = function(o1, o2)
print("custom adding: " .. o1 .. " " .. o1)
return 47 -- everything is 47
print("This should be 47: " .. 1 + 2) -- its 3 not 47