Re: Table constructor question
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Table constructor question
- From: "Soni L." <fakedme@...>
- Date: 2015年1月03日 14:43:11 -0200
Assigning to the same thing on the same _expression_ is undefined. For
example:
$ luac -l -l -
a,a = 1,2
main <stdin:0,0> (4 instructions at 0x222e0c0)
0+ params, 2 slots, 1 upvalue, 0 locals, 3 constants, 0 functions
1 [1] LOADK 0 -2 ; 1
2 [1] SETTABUP 0 -1 -3 ; _ENV "a" 2
3 [1] SETTABUP 0 -1 0 ; _ENV "a"
4 [1] RETURN 0 1
constants (3) for 0x222e0c0:
1 "a"
2 1
3 2
locals (0) for 0x222e0c0:
upvalues (1) for 0x222e0c0:
0 _ENV 1 0
On the other hand, this is actually defined:
local a,a,a = 1,2,3
Due to shadowing, this _expression_ generates 3 locals with the same
name, each with a different value, and the last one takes effect.
(thus, when scanning locals, you should scan them BACKWARDS, not
forwards like most ppl do >.>)
$ luac -l -l -
local a,a,a = 1,2,3
main <stdin:0,0> (4 instructions at 0x14050c0)
0+ params, 3 slots, 1 upvalue, 3 locals, 3 constants, 0 functions
1 [1] LOADK 0 -1 ; 1
2 [1] LOADK 1 -2 ; 2
3 [1] LOADK 2 -3 ; 3
4 [1] RETURN 0 1
constants (3) for 0x14050c0:
1 1
2 2
3 3
locals (3) for 0x14050c0:
0 a 4 5
1 a 4 5
2 a 4 5
upvalues (1) for 0x14050c0:
0 _ENV 1 0
[
--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.