Re: weak_ref issue patch
Glen Fraser <[email protected]> Tue, 23 Jul 2013 12:00:29 +0200
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
--===============4685744505425740166==
Content-Type: multipart/alternative;
boundary="Apple-Mail=_4AF48C8C-055B-4469-AA07-D3301A0D7943"
--Apple-Mail=_4AF48C8C-055B-4469-AA07-D3301A0D7943
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=windows-1252
> 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=20
> 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=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:
boost::shared_ptr<Actor> fromLua =3D =
luabind::call_function<boost::shared_ptr<Actor> >(mLua, =
"makeActorSubclass", "bobby")[luabind::adopt(luabind::result)];
The function makeActorSubclass is a simple Lua script that creates an =
instance of a class derived from Actor in Lua (this creation code works =
fine without the adopt policy stuff...except it doesn't transfer =
ownership to C++, so the object gets garbage-collected later on!).
function makeActorSubclass(name)
return ActorSubclass(name)
end
Any ideas on how to get rid of my const problem? I do see the following =
comment in the luabind docs:
get_const_holder() has been removed. Automatic conversions between =
smart_ptr<X>and smart_ptr<X const> no longer work.
But I'm not sure what that means, and whether it applies in my case (I =
don't have any smart_ptr<X const> usages that I know of).
Glen.
On Jul 23, 2013, at 10:55 AM, Christian <[email protected]> wrote:
> On Tuesday 23 July 2013, at 10:11:13, Glen Fraser <[email protected]> =
wrote:
>> Now, when I try to use the adopt policy, I get errors like Sympaval =
had (in
>> this thread:
>> =
http://lua.2524044.n2.nabble.com/Remove-an-object-from-the-lua-state-tp758=
3
>> 423p7583425.html). He didn't manage to get adopt working when =
binding, but
>> rather chose to instead use it with using call_function.
>>=20
>> Same as him -- I get errors like this, when trying to use adopt(_2) =
in a
>> def():
>>=20
>> .../boost/include/boost/preprocessor/iteration/detail/local.hpp:37:9: =
No
>> member named 'consumed_args' in 'luabind::detail::adopt_policy<2,
>> void>::only_accepts_nonconst_pointers'
>> .../boost/include/boost/preprocessor/iteration/detail/local.hpp:37:9: =
No
>> member named 'converter_postcall' in =
'luabind::detail::adopt_policy<2,
>> void>::only_accepts_nonconst_pointers'
>> .../addons/ofxLua/src/luabind/luabind/detail/call.hpp:295:48: No =
member
>> named 'apply' in 'luabind::detail::adopt_policy<2,
>> void>::only_accepts_nonconst_pointers'
>>=20
>> And when I try to use it with call_function:
>>=20
>> =
.../addons/ofxLua/src/luabind/luabind/detail/call_function.hpp:200:20: =
No
>> member named 'match' in 'luabind::detail::adopt_policy<0,
>> void>::only_accepts_nonconst_pointers'
>>=20
>=20
> 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=20
> be both a pointer and a non-const one).
>=20
> Hope I could help,
> Christian
>=20
--Apple-Mail=_4AF48C8C-055B-4469-AA07-D3301A0D7943
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=windows-1252
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space; =
"><blockquote type=3D"cite">The struct name =
"only_accepts_nonconst_pointers" is meant as an error message:<br>adopt =
only works with non-const pointers (meaning that the adopted type =
must <br>be both a pointer and a non-const =
one).<br></blockquote><div><br></div>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=85<div><br></div><div>I declare my class binding like =
this:</div><div><br></div><div><div style=3D"margin: 0px; font-size: =
14px; font-family: Menlo; color: rgb(49, 89, 93); "><span style=3D"color: =
#000000"> </span>class_<span style=3D"color: =
#000000"><</span>Actor<span style=3D"color: #000000">, =
</span>Actor_wrapper<span style=3D"color: #000000">, =
</span>boost::shared_ptr<Actor> <span style=3D"color: =
#000000">>(</span><span style=3D"color: #d12f1b">"Actor"</span><span =
style=3D"color: #000000">)</span></div><div style=3D"margin: 0px; =
font-size: 14px; font-family: Menlo; color: rgb(49, 89, 93); "><span =
style=3D"color: #000000"> .</span>def<span =
style=3D"color: #000000">(</span>constructor<span style=3D"color: =
#000000"><</span><span style=3D"color: #bb2ca2">const</span><span =
style=3D"color: #000000"> </span>string<span style=3D"color: #000000"> =
&>())</span></div><div style=3D"margin: 0px; font-size: 14px; =
font-family: Menlo; color: rgb(49, 89, 93); "><span style=3D"color: =
#000000"> .</span>def<span style=3D"color: =
#000000">(</span><span style=3D"color: #d12f1b">"draw"</span><span =
style=3D"color: #000000">, &</span>Actor<span style=3D"color: =
#000000">::</span>draw<span style=3D"color: #000000">, =
&</span>Actor_wrapper<span style=3D"color: =
#000000">::</span>default_draw<span style=3D"color: =
#000000">)</span></div><div style=3D"margin: 0px; font-size: 14px; =
font-family: Menlo; "> =
];</div><div><br></div><div>And the function I'm trying to call from C++ =
is like this:</div><div><br></div><div><div style=3D"margin: 0px; =
font-size: 14px; font-family: Menlo; color: rgb(49, 89, 93); "><span =
style=3D"color: #000000"> =
</span>boost::shared_ptr<Actor><span style=3D"color: =
#000000"> fromLua =3D </span><span style=3D"color: =
#4f8187">luabind</span><span style=3D"color: =
#000000">::</span>call_function<span style=3D"color: =
#000000"><</span>boost::shared_ptr<Actor> <span =
style=3D"color: #000000">>(</span>mLua<span style=3D"color: =
#000000">, </span><span style=3D"color: =
#d12f1b">"makeActorSubclass"</span><span style=3D"color: #000000">, =
</span><span style=3D"color: #d12f1b">"bobby"</span><span style=3D"color: =
#000000">)[</span>luabind<span style=3D"color: =
#000000">::</span>adopt<span style=3D"color: =
#000000">(</span>luabind<span style=3D"color: =
#000000">::</span>result<span style=3D"color: =
#000000">)];</span></div></div><div><span style=3D"color: =
#000000"><br></span></div><div><div>The function makeActorSubclass is a =
simple Lua script that creates an instance of a class derived from Actor =
in Lua (this creation code works fine without the adopt policy =
stuff...except it doesn't transfer ownership to C++, so the object gets =
garbage-collected later on!).</div><div><br></div><div><div =
style=3D"margin: 0px; font-size: 14px; font-family: Menlo; color: =
rgb(209, 47, 27); "><span style=3D"color: #000000"> =
</span>function makeActorSubclass(name)</div><div =
style=3D"margin: 0px; font-size: 14px; font-family: Menlo; color: =
rgb(209, 47, 27); "> return =
ActorSubclass(name)</div><div style=3D"margin: 0px; font-size: 14px; =
font-family: Menlo; "> <span style=3D"color: =
#d12f1b">end</span></div></div><div><br></div><div>Any ideas on how to =
get rid of my const problem? I do see the following comment in the =
luabind docs:</div><div><br></div><div><tt class=3D"docutils literal" =
style=3D"margin: 0px; padding: 0px; font-size: 12px; font-family: =
'Courier New', Courier; color: rgb(49, 85, 102); text-align: left; =
background-color: rgb(241, 255, 245); "><span class=3D"pre" =
style=3D"margin: 0px; padding: 0px; =
">get_const_holder()</span></tt><span style=3D"font-family: Verdana; =
font-size: 12px; line-height: 20px; text-align: left; background-color: =
rgb(241, 255, 245); "> has been removed. Automatic conversions =
between </span><tt class=3D"docutils literal" style=3D"margin: 0px; =
padding: 0px; font-size: 12px; font-family: 'Courier New', Courier; =
color: rgb(49, 85, 102); text-align: left; background-color: rgb(241, =
255, 245); "><span class=3D"pre" style=3D"margin: 0px; padding: 0px; =
">smart_ptr<X></span></tt><span style=3D"font-family: Verdana; =
font-size: 12px; line-height: 20px; text-align: left; background-color: =
rgb(241, 255, 245); ">and </span><tt class=3D"docutils literal" =
style=3D"margin: 0px; padding: 0px; font-size: 12px; font-family: =
'Courier New', Courier; color: rgb(49, 85, 102); text-align: left; =
background-color: rgb(241, 255, 245); "><span class=3D"pre" =
style=3D"margin: 0px; padding: 0px; ">smart_ptr<X</span> <span =
class=3D"pre" style=3D"margin: 0px; padding: 0px; =
">const></span></tt><span style=3D"font-family: Verdana; font-size: =
12px; line-height: 20px; text-align: left; background-color: rgb(241, =
255, 245); "> no longer work.</span></div><div><br></div><div>But =
I'm not sure what that means, and whether it applies in my case (I don't =
have any smart_ptr<X const> usages that I know =
of).</div><div><br></div><div>Glen.</div><div><br><div><div>On Jul 23, =
2013, at 10:55 AM, Christian <<a =
href=3D"mailto:[email protected]">[email protected]</a>> =
wrote:</div><br class=3D"Apple-interchange-newline"><blockquote =
type=3D"cite">On Tuesday 23 July 2013, at 10:11:13, Glen Fraser <<a =
href=3D"mailto:[email protected]">[email protected]</a>> =
wrote:<br><blockquote type=3D"cite">Now, when I try to use the adopt =
policy, I get errors like Sympaval had (in<br>this thread:<br><a =
href=3D"http://lua.2524044.n2.nabble.com/Remove-an-object-from-the-lua-sta=
te-tp7583">http://lua.2524044.n2.nabble.com/Remove-an-object-from-the-lua-=
state-tp7583</a><br>423p7583425.html). He didn't manage to get =
adopt working when binding, but<br>rather chose to instead use it with =
using call_function.<br><br>Same as him -- I get errors like this, when =
trying to use adopt(_2) in =
a<br>def():<br><br>.../boost/include/boost/preprocessor/iteration/detail/l=
ocal.hpp:37:9: No<br>member named 'consumed_args' in =
'luabind::detail::adopt_policy<2,<br>void>::only_accepts_nonconst_po=
inters'<br>.../boost/include/boost/preprocessor/iteration/detail/local.hpp=
:37:9: No<br>member named 'converter_postcall' in =
'luabind::detail::adopt_policy<2,<br>void>::only_accepts_nonconst_po=
inters'<br>.../addons/ofxLua/src/luabind/luabind/detail/call.hpp:295:48: =
No member<br>named 'apply' in =
'luabind::detail::adopt_policy<2,<br>void>::only_accepts_nonconst_po=
inters'<br><br>And when I try to use it with =
call_function:<br><br>.../addons/ofxLua/src/luabind/luabind/detail/call_fu=
nction.hpp:200:20: No<br>member named 'match' in =
'luabind::detail::adopt_policy<0,<br>void>::only_accepts_nonconst_po=
inters'<br><br></blockquote><br>The struct name =
"only_accepts_nonconst_pointers" is meant as an error message:<br>adopt =
only works with non-const pointers (meaning that the adopted type must =
<br>be both a pointer and a non-const one).<br><br>Hope I could =
help,<br>Christian<br><br></blockquote></div></div></div></div></body></ht=
ml>=
--Apple-Mail=_4AF48C8C-055B-4469-AA07-D3301A0D7943--
--===============4685744505425740166==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
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
--===============4685744505425740166==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
--===============4685744505425740166==--