Re: Remove Luabind ownership on C++ pointer?
Daniel Wallin <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Sep 30, 2010 at 5:43 PM, neosettlers <[email protected]> wrote: > Hummm... > > Luabind, you’re a guest in my home (C++ library), on your way out, please do not take my garbage with you! (I wish I wouldn’t have to ask) > > No offense but making extra functions or even worst, a manager for this is embarrassing... this should be solved with something like this: > > .def(constructor<>()) > .def(destructor<>()) /// if present, take the garbage out, if not please, mind your own business! Well, this is a very rare request. Having to explicitly state that instances should be destroyed would screw over almost everyone. Basically, you have some class whose instances somehow manages their own lifetime? You can try holding the Lua-created instances in a special smart pointer that doesn't delete: template <class T> struct dummy_ptr { dummy_ptr(T* p_) : p(p_) {} T* p; }; template <class T> T* get_pointer(dummy_ptr<T> const& p) { return p.p; } ... class_<Whatever, dummy_ptr<Whatever> >("Whatever") .def(constructor<>(...)) -- Daniel Wallin BoostPro Computing http://www.boostpro.com ------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev