default_converter and luabind assignment
<[email protected]> Wed, 8 Jan 2014 17:36:41 +0000
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
--===============0486970010114043489==
Content-Language: en-US
Content-Type: multipart/alternative;
boundary="_000_968F113960C5EC44950119195F8CB50C207A32A4HIGH5EXCH1High5_"
--_000_968F113960C5EC44950119195F8CB50C207A32A4HIGH5EXCH1High5_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hi,
I want to add support to a user type in luabind, so that I can assign c++ v=
ariables of the type to lua variables like so:
struct UserType{..};
//and then do
UserType u;
luabind::globals(L)["UserTypeList"]["a"] =3D u; //equivalent to saying User=
TypeList.a =3D u in Lua.
I registered the class type via luabind::class_ and specialized the default=
_converter for the type :
module(L)[ class_< UserType>("_ UserType")];
namespace luabind{
template<>
struct default_converter< UserType> : native_converter_base< UserType> {
//define compute_score, to and from functions.
};
}
But when I actually do the assignment, the converter code doesn't get calle=
d. I'm expecting the 'to' function in the converter to get called, since I'=
m assigning a custom type to a lua object, which doesn't happen.
Is this the correct way to do this. Please let me know if you find any issu=
es with this setup.
Thanks arun.
--_000_968F113960C5EC44950119195F8CB50C207A32A4HIGH5EXCH1High5_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
<meta name=3D"Generator" content=3D"Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div class=3D"WordSection1">
<p class=3D"MsoNormal">Hi, <o:p></o:p></p>
<p class=3D"MsoNormal">I want to add support to a user type in luabind, so =
that I can assign c++ variables of the type to lua variables like s=
o:<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New"">struct UserType{..};
<o:p></o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New""><o:p> </o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New"">//and then do
<o:p></o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New""><o:p> </o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New"">UserType u;<o:p></o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New"">luabind::globals(L)[“UserTypeList”][=
“a”] =3D u; //equivalent to saying UserTypeList.a =3D u i=
n Lua.<o:p></o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New""><o:p> </o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New""><o:p> </o:p></span></p>
<p class=3D"MsoNormal">I registered the class type via luabind::class_ and =
specialized the default_converter for the type :<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New"">module(L)[ class_< UserType>(“_ User=
Type”)];<o:p></o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New""><o:p> </o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New"">namespace luabind{<o:p></o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New""> template<><o:p></=
o:p></span></p>
<p class=3D"MsoNormal" style=3D"margin-left:.5in;text-indent:.5in"><span st=
yle=3D"font-family:"Courier New"">struct default_converter&=
lt; UserType> : native_converter_base< UserType> {<o:p></o:p></spa=
n></p>
<p class=3D"MsoNormal" style=3D"margin-left:.5in;text-indent:.5in"><span st=
yle=3D"font-family:"Courier New""> //defi=
ne compute_score, to and from functions.<o:p></o:p></span></p>
<p class=3D"MsoNormal" style=3D"margin-left:.5in;text-indent:.5in"><span st=
yle=3D"font-family:"Courier New"">};<o:p></o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New"">}<o:p></o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New""><o:p> </o:p></span></p>
<p class=3D"MsoNormal" style=3D"text-indent:.5in"><span style=3D"font-famil=
y:"Courier New""><o:p> </o:p></span></p>
<p class=3D"MsoNormal">But when I actually do the assignment, the converter=
code doesn’t get called. I’m expecting the ‘to’ fu=
nction in the converter to get called, since I’m assigning a custom&n=
bsp; type to a lua object, which doesn’t happen.
<o:p></o:p></p>
<p class=3D"MsoNormal">Is this the correct way to do this. Please let me kn=
ow if you find any issues with this setup.
<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Thanks arun.<o:p></o:p></p>
</div>
</body>
</html>
--_000_968F113960C5EC44950119195F8CB50C207A32A4HIGH5EXCH1High5_--
--===============0486970010114043489==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
--===============0486970010114043489==
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
--===============0486970010114043489==--