lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Excerpts from Tony Finch's message of Fri Apr 23 21:39:03 +0100 2010:
> 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.
> 

Yes, you're right - that's of course what I meant - thanks :)

Coercion in comparisons would be far too PHP-like...

Matthew