Re: Remove Luabind ownership on C++ pointer?

neosettlers <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
  class_<Whatever, Whatever*>("Whatever")

Makes luabind hold the newly created instance in a raw Whatever*, and thus
won't delete it.

Awesome, even better! Is this mentioned anywhere in the doc?

Thank you. 

-----Original Message-----
From: Daniel Wallin [mailto:[email protected]] 
Sent: Friday, October 01, 2010 5:28 AM
To: [email protected]
Subject: Re: [luabind] Remove Luabind ownership on C++ pointer?

On Fri, Oct 1, 2010 at 12:15 AM, neosettlers <[email protected]>
wrote:
> Thx everyone for the inputs,
>
>> Well, this is a very rare request. Having to explicitly state that 
>> instances should be destroyed would screw over almost everyone.
>
> I think it is at least practical to have the choice to managed your 
> memory yourself without reinventing the wheel.

Sure, and you do have that choice.

>> Basically, you have some class whose instances somehow manages their 
>> own lifetime?
>
> Of course, all classes are registered and unregister by an object manager.

Right. Typically this would be done by either:

  1. Creating the object in lua, and then have some function on the manager
      that explicitly takes ownership, or...

  2. Having a factory function on your manager that creates the object and
      returns non owning pointer.

(2) works automatically, and luabind has adopt() for (1). Perhaps we should
have a release_ownership() policy similar to adopt(), that can be used
post-construction, I'm not sure. That said, I believe your problem can be
handled as I show below.

> I managed to solved my problem in modifying the source directly:
>
> object_rep::~object_rep()
> {
>        if (!m_instance)
>            return;
>  ///    m_instance->~instance_holder();
>        deallocate(m_instance);
> }

Did you try what I posted? In fact, it can be done in an even simpler way:

  class_<Whatever, Whatever*>("Whatever")

Makes luabind hold the newly created instance in a raw Whatever*, and thus
won't delete it.

--
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
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.