lua-users home
lua-l archive

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


On Thu, 15 Nov 2018 at 20:49, Egor Skriptunoff
<egor.skriptunoff@gmail.com> wrote:
>
> On Mon, Jun 18, 2018 at 11:33 PM Luiz Henrique de Figueiredo wrote:
>>
>> Lua 5.4.0 (work2) is now available for testing
>
>
>
> The manual says:
> for v = e1, e2, e3 do block end
> is equivalent to the code:
> do
>   local var, limit, step = tonumber(e1), tonumber(e2), tonumber(e3)
>   ...
>
>
> If tonumber("1") is integer, why does loop variable contain float value?
>
> > tonumber("1")
> 1
> > for j = "1", 2 do print(j) end
> 1.0
> 2.0
>

I think this option might help:

/*
@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a
@@ a float mark ('.0').
** This macro is not on by default even in compatibility mode,
** because this is not really an incompatibility.
*/
/* #define LUA_COMPAT_FLOATSTRING */