lua-users home
lua-l archive

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



I guess that would also mean that the GETUPTAB and SETUPTAB opcodes are
not only generated for indexing _ENV, but for all tables which are
upvalues?

I've managed to answer this myself (luac works now yay!), but just for the curious.

Just to clarify the question, if I say:

local foo = { answer = 42 }
function frob()
   print(foo.answer)
end

Should I see a GETTABUP for "foo.answer"?

luac says we do! That's cool.

function <foo.lua:2,4> (4 instructions, 16 bytes at 0x1593620)
0 params, 2 slots, 2 upvalues, 0 locals, 2 constants, 0 functions
	1	[3]	GETTABUP 	0 0 -1	; _ENV "print"
	2	[3]	GETTABUP 	1 1 -2	; foo "answer"
	3	[3]	CALL     	0 2 1
	4	[4]	RETURN   	0 1

And this guy:

local foo = { greet = function() print "Hi" end }
function frob()
   foo:greet()
end

... as expected has SELF preceded by GETUPVAL:
function <foo.lua:2,4> (4 instructions, 16 bytes at 0x1298620)
0 params, 2 slots, 1 upvalue, 0 locals, 1 constant, 0 functions
	1	[3]	GETUPVAL 	0 0	; foo
	2	[3]	SELF     	0 0 -1	; "greet"
	3	[3]	CALL     	0 2 1
	4	[4]	RETURN   	0 1


Cheers,
Rich