Re: Problem with boost::shared_ptr auto conversion
Daniel Wallin <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Aug 25, 2010 at 1:13 PM, Daniel Herb <[email protected]> wrote: > Hello, > I'm pretty new to luabind and got a problem with boost::shared_ptr: > > If you have the following functions: > Foo getFoo(); > void setFoo(boost::shared_ptr<Foo> foo); > > which are registered with luabind: > luabind::class_<Foo, boost::shared_ptr<Foo> >("Foo"), > luabind::def("getFoo", &getFoo), > luabind::def("setFoo", &setFoo) > > this lua-code doesn't work: > setFoo(getFoo()); > > Why? All other conversions are handled completely automatically (which is > pretty nice). > Have I missed something? Well, the object returned by getFoo() isn't held by a shared_ptr<Foo>. The copy is actually held in a std::auto_ptr<Foo>, but that's an implementation detail. Specifically for shared_ptr, it's actually possible to get this to work. Simply including <luabind/shared_ptr_converter.hpp> should work for you. -- Daniel Wallin BoostPro Computing http://www.boostpro.com ------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd