[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C API question
- From: joao lobato <btnfdp.lobato@...>
- Date: Fri, 7 Jan 2011 16:54:11 +0000
On 1/7/11, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>> I would be happy to see refs go away because they seem like a sharp,
>> tempting feature that actually doesn't add value.
>>
>> If your userdata object needs to reference other Lua data, you
>> really, really, really want to use the environment mechanism because
>> this works with the GC whereas refs are very prone to creating
>> uncollectable cycles.
>>
>> If your C code needs to reference a Lua value, I tend to recommend
>> using light userdata keys in the registry bearing in mind that this
>> creates anchors for the GC.
>
> Exactly. The archetypal use of references were a full userdata keeping
> references to other Lua values by keeping in its C structure the
> integers returned by luaL_ref. The finalizer for this userdata should be
> responsible to release its references when the userdata was collected.
> This kind of use became obsolete with environments.
>
> Does anyone still use references in real applications? For what?
>
> -- Roberto
>
>
>
Well, for my part thanks again. I wasn't aware of the environment
mechanism for userdata (I thought it was only for functions). It seems
I was using correctly (mostly, at least) an outdated mechanism...
For what it is worth, I'd say off with the reference system:
lightuserdata seems much cleaner.