[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Metamethods as weak reference?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 1 Jun 2011 09:27:57 -0300
> 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