[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: String-to-number coercion
- From: Mike Nelson <mikestar1313@...>
- Date: Sun, 15 Sep 2013 19:46:35 -0700
On 9/15/2013 5:26 PM, Luiz Henrique de Figueiredo wrote:
2013/9/10 Andrew Starks <firstname.lastname@example.org>:
In my very humble opinion (and despite my own transgressions into
discussions on its redesign :), it gets this balance perfectly... Except
when it prompts strings to numbers. .)
More precisely: the exact spot where this irks me is that if you set
metamethods for str:__add etc, they don't get invoked when tonumber()
succeeds for both operands, EVEN WHEN BOTH ARE STRINGS.
Wthat do you mean, exactly? Can you please give an example?
error("can't add strings, you know") end})
this prints 3 rather than raising an error.
change the last line to print("1"+"ZZ")
and the error in the above metatable is raised, rather than the standard
"attempt to perform arithmetic on a string value".