Re: Remove Luabind ownership on C++ pointer?
Iliya Trendafilov <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Another option is to register a factory function instead of constructor.
E.g.
C++
Object* CreateObject() { return new Object(); }
module(lua)
[
class_<Object>("Object")
.def("CreateObject", &CreateObject)
];
Lua:
local object = CreateObject();
You'll be solely responsible for deleting these objects in that case.
Another thing I did once is to keep a Lua table with all created instances.
In Lua:
function CreateObject(...)
objects = objects or {}
local object = Object()
table.insert(objects, object)
return object
end
and then create all your instances through that function.
I'll leave you to decide which of the methods is the most elegant :)
On Thu, Sep 30, 2010 at 1:30 PM, eduard mueller <
[email protected]> wrote:
> Hold the object in a boost::shared_ptr or some other reference
> counting smart_ptr in Lua:
> class_<Object, boost::shared_ptr<Object> >("Object")
>
> Then the object will be kept alive as long as another shared_ptr uses
> the object in C++. Aka, the instance that is created in Lua will only
> release the shared pointer, not destruct the object itself when
> garbage collected.
>
> Best regards,
> Eduard
>
>
> On Thu, Sep 30, 2010 at 05:16, neosettlers <[email protected]>
> wrote:
> > Greetings,
> >
> >
> >
> > I’m wondering how to remove Luabind ownership on C++ pointers:
> >
> >
> >
> > C++
> >
> > module(lua)
> >
> > [
> >
> > class_<Object>("Object")
> >
> > .def(constructor<>())
> >
> > ];
> >
> >
> >
> > .lua
> >
> > local object = Object();
> >
> >
> >
> > …
> >
> >
> >
> > I would like Luabind NOT to delete the object C++ pointer when lua_gc()
> is
> > called.
> >
> >
> >
> > If anyone found an elegant solution for this, I’m definitely interested
> to
> > hear about it.
> >
> >
> >
> > Thx,
> >
> >
> >
> >
> >
> >
> ------------------------------------------------------------------------------
> > 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
> _______________________________________________
> 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
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user