lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Jul 30, 2011, at 11:01 AM, Gregory Bonik wrote:

> Thanks a lot, it sounds like a solution. However, I don't like tracking
> these transitions, so I came up with an idea of something like garbage
> collection.
> 
> I could create a fully strong (sic!) table in the registry, let's call
> it "objects table", and store there a map between C++ objects (as light
> userdata) and their full userdatas (which will be guaranteed to be
> unique per object). Callbacks can be stored in the userdata's env table.
> 
> Periodically, a "garbage collection" procedure is triggered. It
> traverses the objects table. All objects in the table with reference
> count equal to 1 are removed from the table.
> 
> When an object with reference count equal to 1 is pushed from Lua to C++
> function, it is added back to the objects table.

This is almost exactly the system that Lightroom uses. It just seemed more complicated to describe in e-mail and count on people getting right.

(My latest project is written with the provision that objects just need to be prepared for their Lua-side counterparts to go away.)

Mark