lua-users home
lua-l archive

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


> I'm wondering if a statement like this:
> 
>     x, y = math.pi/2, math.pi/4
> 
> which doesn't need the extra work, would be less efficient than this:
> 
>     x = math.pi/2
>     y = math.pi/4

No, they generate essentially the same code, except for when the values
are assigned to x and y:

-- x, y = math.pi/2, math.pi/4
	1	[1]	GETTABUP 	0 0 -3	; _ENV "math"
	2	[1]	GETTABLE 	0 0 -4	; "pi"
	3	[1]	DIV      	0 0 -5	; - 2
	4	[1]	GETTABUP 	1 0 -3	; _ENV "math"
	5	[1]	GETTABLE 	1 1 -4	; "pi"
	6	[1]	DIV      	1 1 -6	; - 4
	7	[1]	SETTABUP 	0 -2 1	; _ENV "y"
	8	[1]	SETTABUP 	0 -1 0	; _ENV "x"
	9	[1]	RETURN   	0 1

-- x = math.pi/2 ; y = math.pi/4
	1	[1]	GETTABUP 	0 0 -2	; _ENV "math"
	2	[1]	GETTABLE 	0 0 -3	; "pi"
	3	[1]	DIV      	0 0 -4	; - 2
	4	[1]	SETTABUP 	0 -1 0	; _ENV "x"
	5	[2]	GETTABUP 	0 0 -2	; _ENV "math"
	6	[2]	GETTABLE 	0 0 -3	; "pi"
	7	[2]	DIV      	0 0 -6	; - 4
	8	[2]	SETTABUP 	0 -5 0	; _ENV "y"
	9	[2]	RETURN   	0 1