lua-users home
lua-l archive

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



You don't necessarily need to make the userdata itself be the C++ pointer. This way, you can invalidate a userdata (in C++) without needing it to be garbage collected right there and then. Of course, any access to such in Lua world would need to check its validity first. And the actual garbage collector would skip it if it's already dead.

There may be other approaches, I too am eager to hear them. :)

-asko


Wesley Smith kirjoitti 15.2.2007 kello 8.32:

Hi Collective Wisdom,
I'm struggling with a design issue in integrating Lua into a C++
library.  The way the library is designed, the destructor of an object
can create a cascade of destructor calls some of which could
potentially be resources referred to in Lua.  The problem I'm trying
to solve right now is how to manage freeing userdata in Lua once a C++
object having nothing to do with Lua destroys it.  Are there idioms
people use for dealing with this kind of thing?

thanks,
wes