Re: weak_ref issue patch
Glen Fraser <[email protected]> Sun, 28 Jul 2013 20:33:12 +0200
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
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 construct= or? What I tried is this: when I add a new object (wherever it comes from) to m= y C++ container, I run a method based on your code below -- if the object b= eing added to my C++ container is based on the Lua wrapper class (tested us= ing dynamic_cast), then I get its luabind wrapped_self_t and set its "stron= g 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 refer= ence 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 creat= e a matching function, that calls reset() on its m_strong_ref? Thanks, Glen. On Jul 23, 2013, at 12:20 PM, Christian <[email protected]> wrote: > On Tuesday 23 July 2013, at 12:00:29, Glen Fraser <[email protected]> wr= ote: >>> 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. Presum= ably >> 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=85 >> = >> 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 =3D = > 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 a= t = > 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=3D48808831&iu=3D/4140/ostg.= clktrk > _______________________________________________ > luabind-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/luabind-user ---------------------------------------------------------------------------= --- 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=3D48808831&iu=3D/4140/ostg.cl= ktrk