lua-users home
lua-l archive

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


Hi,

Lua 5.3.0  Copyright (C) 1994-2015 Lua.org, PUC-Rio

First, here are some bits from the manual:

Coercions and Conversions http://www.lua.org/manual/5.3/manual.html#3.4.3
[...], the string is converted to an integer or a float, following its syntax and the rules of the Lua lexer.

Lexical Conventions http://www.lua.org/manual/5.3/manual.html#3.1
A numeric constant with a fractional dot or an exponent denotes a float; otherwise it denotes an integer.

so working backwards:

0 and 1 both get parsed by the lexer as integers.

> print(0+1)
1
> print(math.type(0+1))
integer

tonumber() also parses "0" to an integer:

> print(tonumber("0")+1)
1
> print(math.type(tonumber("0")+1))
integer

yet without the explicit conversion it ends up as a float:

> print("0"+1)
1.0
> print(math.type("0"+1))
float

Andrew