[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Some questions and proposals about GC and memory management in Lua
- From: Leo Romanoff <romixlev@...>
- Date: Wed, 24 Jul 2013 13:09:01 -0700 (PDT)
----- Ursprüngliche Message -----
> Von: TNHarris <email@example.com>
> An: firstname.lastname@example.org
> Gesendet: 21:03 Mittwoch, 24.Juli 2013
> Betreff: Re: Some questions and proposals about GC and memory management in Lua
> On Wednesday, July 24, 2013 01:08:30 PM Leo Romanoff wrote:
>> - Yet another issue, where I'm not sure about what's possible
>> today, is the ability to refer to Lua objects from userdata objects. Is it
>> possible today? I.e. can I create a userdata C-array which refers to Lua
>> objects directly? IMHO, it is not the case today, because it would
>> introduce problems with current GC implementations as they are not able to
>> trace inside userdata objects. But I think that being able to refer to Lua
>> objects from userdata could be very useful for an efficient implementation
>> of many data structures.
> lua_setuservalue and lua_getuservalue do this. It associates a table with a
> userdata. The UD then can store any values it needs in its private table. In a
> past life, this was done with lua_setfenv.
OK. It is probably a workaround. So, I put all Lua values I need to reference from my UD in this table.
"All problems in computer science can be solved by another level of indirection" :-)
(BTW, I can set uservalue and metatable for a userdata separately, right? It is not need to be the same reference?)
The only drawback I would expect is that I need an additional table access every time when I need to access a Lua object. Therefore I'm not sure about the "efficient" part of my requirement.
My original idea was to store real references to Lua objects somewhere inside the UD. Since Lua would not know where to find those pointers inside UD, it would need to use the __trace method from a UD metatable.