lua-users home
lua-l archive

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


> why print negative numbers -1 -2?

Local variables (and other registers) are given positive indices.
Constants are given negative indices.

Consider this program:
	a=1
	local b,c
	a=c

luac -l -l on this gives

	1	[1]	SETTABUP 	0 -1 -2	; _ENV "a" 1
	2	[2]	LOADNIL  	0 1
	3	[3]	SETTABUP 	0 -1 1	; _ENV "a"
	4	[3]	RETURN   	0 1
constants (2) for 0x7f9308c016d0:
	1	"a"
	2	1
locals (2) for 0x7f9308c016d0:
	0	b	3	5
	1	c	3	5
upvalues (1) for 0x7f9308c016d0:
	0	_ENV	1	0

So -1 and -2 refer to constants and 1 refers to the local variable #1, c.