Re: [luabind] weak_ref issue patch
Brought to you by:
arvidn,
daniel_wallin
From: Glen F. <hol...@gm...> - 2013-07-28 18:33:25
|
Okay, thanks. I wasn't 100% sure where you meant I should put this code -- i.e. where you call your bindLuaPart(). In the wrapper object's constructor? What I tried is this: when I add a new object (wherever it comes from) to my C++ container, I run a method based on your code below -- if the object being added to my C++ container is based on the Lua wrapper class (tested using dynamic_cast), then I get its luabind wrapped_self_t and set its "strong ref" as in your code. This seems to work, thanks! I hope this "fix" (hack?) remains more or less valid for future updates to luabind (if there ever are any ;-). Can you explain what this is doing? I guess it just creates a strong reference to the Lua object, so it doesn't get garbage collected? Do I need to do anything specific if the C++ object gets deleted (e.g. in its destructor), to release this strong reference to the Lua-side object? Should I create a matching function, that calls reset() on its m_strong_ref? Thanks, Glen. On Jul 23, 2013, at 12:20 PM, Christian <neu...@ya...> wrote: > On Tuesday 23 July 2013, at 12:00:29, Glen Fraser <hol...@gm...> wrote: >>> The struct name "only_accepts_nonconst_pointers" is meant as an error >>> message: adopt only works with non-const pointers (meaning that the >>> adopted type must be both a pointer and a non-const one). >> >> Thanks, Christian -- I saw that, but I don't know how to fix it. Presumably >> this is related to the fact that the object I'm trying to "adopt" is held >> in a smart pointer (boost::shared_ptr). But I haven't declared the >> smart_ptr as const anywhere… >> >> I declare my class binding like this: >> >> class_<Actor, Actor_wrapper, boost::shared_ptr<Actor> >("Actor") >> .def(constructor<const string &>()) >> .def("draw", &Actor::draw, &Actor_wrapper::default_draw) >> ]; >> >> And the function I'm trying to call from C++ is like this: > Sorry, I hit accidentaly sent my message before it was finished, here is the > function: > > void bindLuaPart() > { > luabind::wrapped_self_t& wrapper = > luabind::detail::wrap_access::ref(*this); > if (wrapper.m_strong_ref.is_valid()) { > LOG_W("Double call to wrap_Component::bindLuaPart"); > return; > } > wrapper.get(wrapper.state()); > wrapper.m_strong_ref.set(wrapper.state()); > } > > This is highly dependent on implementation details though, but it works at > least with the original luabind. > > ------------------------------------------------------------------------------ > See everything from the browser to the database with AppDynamics > Get end-to-end visibility with application monitoring from AppDynamics > Isolate bottlenecks and diagnose root cause in seconds. > Start your free trial of AppDynamics Pro today! > http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk > _______________________________________________ > luabind-user mailing list > lua...@li... > https://lists.sourceforge.net/lists/listinfo/luabind-user |