[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: print("0"+1)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 25 Mar 2015 16:53:06 +0200
2015-03-25 15:37 GMT+02:00 Andrew Cagney <firstname.lastname@example.org>:
> 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.
> tonumber() also parses "0" to an integer:
> yet without the explicit conversion it ends up as a float:
There was a full discussion on this at about the rc1 stage, but I am
not a good looker-up of archives. The basic point is that Lua does
not have coerce-to-integer, only coerce-to-number, whatever
default number is (it can be configured to have no floats). However,
tonumber is an explicit conversion, not a coercion, and parsing is