[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Re: setfenv
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Sun, 12 Oct 2003 23:46:13 -0200
>>There are no references from env tables to functions, only the other way around.
>Can you explain further please?
Lua does not keep a list of all functions that have a given table as their
environment table. Of course, it does keep track of the environment of each
function. The same holds for metatables. Of course, garbage collection makes
sure that of no references exist for a table, then it can be collected.
>I am struggling a little with the following code
>for k,v in pairs(g) do print(k,v) end
>lua5: t3.lua:9: attempt to call a nil value
The problem is that g does not contain a function called "next", which "pairs"
needs. You'll have to add it by hand:
The reason why "next" is not found when "pairs" is called is that "pairs" does
a lua_rawget for "next" and so avoids the _index metamethod. Perhaps "pairs"
should use lua_gettable instead of lua_rawget.