lua-users home
lua-l archive

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

2015-01-16 21:41 GMT+02:00 Lorenzo Donati <>:
> Hi all!
> I just found something that seems odd in Lua 5.3.
> According to sect 3.4.3 in the refman:
> "The conversion from strings to numbers goes as follows: First, the string
> is converted to an integer or a float, following its syntax and the rules of
> the Lua lexer. (The string may have also leading and trailing spaces and a
> sign.) Then, the resulting number is converted to the required type (float
> or integer) according to the previous rules."
> Thus if I have a string which is "42" it should be coerced to an integer,
> since 42 is parsed as an integer constant by the lexer, whereas I get:
> print( 43, "42" + 1 ) --> 43   43.0
> where it seems that the addition is a float addition, signaling that one of
> the operands is float. Is this a bug, an error in the refman or maybe
> something on my side (Windows 7-64, using 32bit executables compiled with
> TDM-GCC 4.9.2 32 bit)? Am I missing something?

It also happens under Ubuntu 14.04 LTS. But:

   print( 43, tonumber"42" + 1 ) --> 43   43

Let's be careful with the word "bug", shall we? Don't want to annoy people.
But certainly this seems to be a documentation/implementation anomaly.