lua-users home
lua-l archive

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


> IIRC, the way Lua constructs tables internally is to push all the initialiser
> elements onto the stack, and then construct the table with a single VM
> opcode...

No, it creates the table first with the NEWTABLE instruction:

% echo 'a={10,20,x="foo"}' | luac -l -

main <stdin:0,0> (7 instructions, 28 bytes at 0x9dbeb30)
0+ params, 3 slots, 0 upvalues, 0 locals, 5 constants, 0 functions
        1       [1]     NEWTABLE        0 2 1
        2       [1]     LOADK           1 -2    ; 10
        3       [1]     LOADK           2 -3    ; 20
        4       [1]     SETTABLE        0 -4 -5 ; "x" "foo"
        5       [1]     SETLIST         0 2 1   ; 1
        6       [1]     SETGLOBAL       0 -1    ; a
        7       [1]     RETURN          0 1