lua-users home
lua-l archive

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


> In Lua 5.2, the code is:
> 
> 	1	[2]	LOADNIL  	0 0
> 	2	[3]	CLOSURE  	1 0	; 0x9198c18
> 	3	[3]	SETTABUP 	0 -1 1	; _ENV "x"
> 	4	[3]	JMP      	1 -4	; to 1
> 	5	[3]	JMP      	0 -5	; to 1
> 	6	[4]	RETURN   	0 1
> 
> The second JMP (never reached) does look mysterious…

The second JMP is the "official" one. 5.2 changed CLOSE to
"close-and-jump" (called JMP), so the first JMP was created
by the end-of-scope of the local variable. Without the closure,
only the second JMP is generated.

(If you compile "do local a; x = function () return a end; end" in
5.2 you will see more clearly this "close-and-jump".)

-- Roberto