[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Make sure numbers are numbers
- From: Tony Finch <dot@...>
- Date: Fri, 23 Apr 2010 21:39:03 +0100
On Wed, 21 Apr 2010, Matthew Wild wrote:
>
> Lua generally doesn't do coercion as a rule (compared to some languages,
> such as PHP).
Yes.
> It generally only coerces numbers<>strings when doing direct comparisons
> (that otherwise wouldn't make sense) or a function indicates (by using
> tostring/lua_tostring) that it is expecting a string, and the user
> passed a number (or vice-versa).
No.
Lua only coerces strings to numbers if they are arguments of an arithmetic
operator (+-*/%^) and numbers to strings if they are arguments of the
concatenation operator. Comparisons preserve types. Functions may coerce
as they require.
Tony.
--
f.anthony.n.finch <dot@dotat.at> http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.