lua-users home
lua-l archive

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


I've managed to get confused about lexical scoping and am away from my normal computer so I can't test this out. What happens if you return a subfunction that accesses local variables in the outer function's scope? Something like this:

function outer()
	local x = 0
	function inner()
		x = x + 1
		print(x)
	end
	inner() -- should print "1"
	return inner
end

x = 12
f = outer()
f() -- what does this do?  runtime error?
print(x) -- I assume this prints "12"

Thanks,
Russ