lua-users home
lua-l archive

Re: tolua++ porting to 5.2

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


On 16/01/2013 8:23 AM, Tim Mensch wrote:
The "weaktable" keeps a weak reference to the existing Lua USERDATA, so
when I "push" an object from C++ and there is an existing Lua object, it
can push a reference to it rather than creating a new Lua USERDATA (I
find that, in games especially, you end up with a LOT of extra garbage
collection if you have to create a new USERDATA every time you want C++
to push the object). While the main object USERDATA exists, maintable[2]
holds a strong C++ reference (shared_ptr) to the object, so it won't be
deleted on the C++ side. When the USERDATA ends up being garbage
collected, the shared_ptr<> is deleted, releasing the C++ reference.
Hi Tim,
One question: Am I correct to assume that this requires that all C++ classes that can be referenced from Lua have their lifetimes managed using shared_ptr in the C++ code as well? That kind of precludes binding an existing code base that does not (and/or can not) use shared_ptr doesn't it?
Thanks,
Ross.

AltStyle によって変換されたページ (->オリジナル) /