[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.3: wrong coercion?
- From: Enrico Tassi <gares@...>
- Date: Fri, 16 Jan 2015 22:44:27 +0100
On Fri, Jan 16, 2015 at 01:35:35PM -0800, Tim Hill wrote:
> print(“42” + 1)
> —> 43.0
> print(tonumber(“42”) + 1)
> —> 43
I've to admit I was puzzled too... but I guess we all want
print("42" + 1)
to behave like
local x = "42"
print(x + 1)
so the ony coercion triggered here is the one documented for arithmetic
operatos, that clearly turns "42" into "42.0" (x is a string, we want
no coercion mapping "42" into an int/float in my second example).
Best,
--
Enrico Tassi