[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Arithmetic on strings
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 13 Jun 2012 15:14:24 -0300
> Concerning (2): not all types have metatables so boolean is still
> somewhat of a problem then. (I can live with it.)
We can use the metatables for strings (if at least one argument is
a string)! This already works both in 5.1 and 5.2:
mt = getmetatable("")
mt.__concat = function (a,b)
return tostring(a) .. tostring(b)
end
print("result: " .. {}) --> result: table: 0x8172130
print(false .. " x " .. true) --> false x true
-- Roberto
- References:
- Re: Arithmetic on strings, Andrew Starks
- Re: Arithmetic on strings, steve donovan
- Re: Arithmetic on strings, liam mail
- Re: Arithmetic on strings, Andrew Starks
- Re: Arithmetic on strings, Javier Guerra Giraldez
- Re: Arithmetic on strings, Roberto Ierusalimschy
- Re: Arithmetic on strings, liam mail
- Re: Arithmetic on strings, Hans Hagen
- Re: Arithmetic on strings, Roberto Ierusalimschy
- Re: Arithmetic on strings, Hans Hagen