local EntityList = {}
function main()
EntityList[0] = { foo = "bar" }
local EntityVar_mt = { __mode = "kv", __index = EntityList[0], __newindex = EntityList[0] }
local EntityVar = {}
setmetatable( EntityVar, EntityVar_mt )
print(EntityVar.foo)
EntityList[0] = nil
print(EntityVar.foo)
end
main()
In this example, I'd expect the following output:
bar
nil
but I get:
bar
bar
On 1 June 2011 13:27, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> It seems all of the metamethods retain a strong reference, which is causing
> me problems trying to use proxy objects. Is there a specific reason they're
> a strong reference? It seems to be this line that makes them all strong:
>
> ltm.c: 39
> for (i=0; i<TM_N; i++) {
> G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);
> luaS_fix(G(L)->tmname[i]); /* never collect these names */
>
> What would be the implications of removing this luaS_fix on the metamethods?
This 'fix' only prevents the collection of the strings '__add', '__index',
etc. (Anyway, strings are never removed by themselves from weak tables.)
If your metatable has weak values, then its entries will be cleared
when the values are no longer accessible.
-- Roberto