lua-users home
lua-l archive

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


2011/11/24 Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>:
> Lua 5.2.0 (rc1) is now available at
>        http://www.lua.org/work/lua-5.2.0-rc1.tar.gz
>
>
> All feedback welcome. Thanks.
> --lhf
>
>

Hello,

I just noticed the following:

3.1 – Lexical Conventions

A numerical constant can be written...

As I understand it, there is no such thing as a negative numerical
constant. However, these do exist:
>luac -l -
a = -3
^Z

main <stdin:0,0> (3 instructions, 12 bytes at 00271598)
0+ params, 2 slots, 0 upvalues, 0 locals, 2 constants, 0 functions
        1       [1]     LOADK           0 -2    ; -3
        2       [1]     SETGLOBAL       0 -1    ; a
        3       [1]     RETURN          0 1

Maybe it would be worth mentioning that a negative sign prefix may
actually be part of the constant?
In fact, one can prefix the constant value with any number of unary
minus, they will be folded in to the mantissa we find in the bytecode.
Even if said unary minus is separated from the mantissa by a
whitespace:

>luac -l -
a=- - 3
^Z

main <stdin:0,0> (3 instructions, 12 bytes at 00861510)
0+ params, 2 slots, 0 upvalues, 0 locals, 2 constants, 0 functions
        1       [1]     LOADK           0 -2    ; 3
        2       [1]     SETGLOBAL       0 -1    ; a
        3       [1]     RETURN          0 1

-- 
Benoit.