lua-users home
lua-l archive

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


On Sat, Jul 3, 2010 at 04:31, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> Specifically, at levels 2 to 5, it returns nil for the variables'
>> names and values. Beyond level 5 it still manages to retrieve correct
>> information.
>
> Are the functions at those levels C functions? If they are Lua functions,
> are they loaded from stripped precompiled files?
>

After some further investigation, I narrowed down the exact problem:
Using tail calls, the calling function's environment is unavailable.
e.g.:

function part1()
	local v_part1 = "one"
	local x = part2()
	return x
end

function part2()
	local v_part2 = "two"
	return part3()
end

function part3()
	local v_part3 = "three"
	part4()
end

If part4() calls debug.getlocal(), it returns no information for level
4 (what should be the environment of part2).
part1() avoids this problem by not performing a tail call, but is
there any better way to access that environment, or is it lost
forever? And then why does the tail call leave an "empty" level
instead of nothing at all?

-- 
Sent from my toaster.