Re: How to get Lua class name from C++ class?
"Christian" <[email protected]> Wed, 28 Aug 2013 16:07:11 +0200
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
This is a multipart message in MIME format. --===============2108133576143098204== Content-Type: multipart/alternative; boundary="----=_NextPart_000_0019_01CEA408.AA0CEAF0" Content-Language: de-at This is a multipart message in MIME format. ------=_NextPart_000_0019_01CEA408.AA0CEAF0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Just replace luabind::object with luabind::argument in your code. They = work both the same, only that the first stores the referenced object in = the registry, while the latter just leaves it on the stack. =20 If you ever have to convert one into another, just use the ones push() = method and the others from_stack constructor (but avoid relative indices = with luabind::argument). =20 From: Glen Fraser [mailto:[email protected]]=20 Sent: Wednesday, August 28, 2013 1:09 PM To: [email protected] Subject: [luabind] How to get Lua class name from C++ class? =20 Hello there, I'm using luabind and trying to get the Lua subclass name = from an instance of the base class in C++. =20 I want to use get_class_info(), but it expects an "argument" rather than = an "object". Perhaps there is a better way to do this, besides trying = to figure out how to convert a luabind::object into a = luabind::adl::argument=E2=80=A6 Here is some example code that should = illustrate the problem: =20 class BaseClass { public: virtual ~BaseClass() {} std::string getClassName(lua_State* L); // ... more stuff... }; =20 class BaseClass_wrapper : public BaseClass, public luabind::wrap_base { // ... some stuff... }; =20 std::string BaseClass::getClassName(lua_State* L) { BaseClass_wrapper* p =3D dynamic_cast<BaseClass_wrapper*>(this); std::string className("UNKNOWN"); if (p !=3D 0) { luabind::object myObject(L, p); luabind::class_info info =3D luabind::get_class_info(myObject); = // no good! // no viable conversion from 'luabind::object' to 'const = luabind::adl::argument' className =3D info.name; } return className; } =20 =20 Thanks for any suggestions, Glen. =20 ------=_NextPart_000_0019_01CEA408.AA0CEAF0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; = charset=3Dutf-8"> <html xmlns:v=3D"urn:schemas-microsoft-com:vml" = xmlns:o=3D"urn:schemas-microsoft-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 name=3DGenerator = 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;} @font-face {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4;} @font-face {font-family:Menlo; panose-1:0 0 0 0 0 0 0 0 0 0;} @font-face {font-family:Consolas; panose-1:2 11 6 9 2 2 4 3 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman","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.E-MailFormatvorlage17 {mso-style-type:personal-reply; font-family:"Calibri","sans-serif"; color:windowtext;} .MsoChpDefault {mso-style-type:export-only; font-size:10.0pt;} @page WordSection1 {size:612.0pt 792.0pt; margin:70.85pt 70.85pt 2.0cm 70.85pt;} 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=3DDE-AT link=3Dblue = vlink=3Dpurple><div class=3DWordSection1><p class=3DMsoNormal><span = lang=3DEN-US style=3D'font-size:11.0pt'>Just replace</span><span = lang=3DEN-US style=3D'font-size:11.0pt;font-family:Consolas'> = luabind::object</span><span lang=3DEN-US style=3D'font-size:11.0pt'> = with </span><span lang=3DEN-US = style=3D'font-size:11.0pt;font-family:Consolas'>luabind::argument</span><= span lang=3DEN-US style=3D'font-size:11.0pt'> in your code. They work = both the same, only that the first stores the referenced object in the = registry, while the latter just leaves it on the = stack.<o:p></o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US = style=3D'font-size:11.0pt'><o:p> </o:p></span></p><p = class=3DMsoNormal><span lang=3DEN-US style=3D'font-size:11.0pt'>If you = ever have to convert one into another, just use the ones </span><span = lang=3DEN-US = style=3D'font-size:11.0pt;font-family:Consolas'>push()</span><span = lang=3DEN-US style=3D'font-size:11.0pt'> method and the others = </span><span lang=3DEN-US = style=3D'font-size:11.0pt;font-family:Consolas'>from_stack</span><span = lang=3DEN-US style=3D'font-size:11.0pt'> constructor (but avoid relative = indices with</span><span lang=3DEN-US = style=3D'font-size:11.0pt;font-family:Consolas'> = luabind::argument</span><span lang=3DEN-US = style=3D'font-size:11.0pt'>).<o:p></o:p></span></p><p = class=3DMsoNormal><span lang=3DEN-US = style=3D'font-size:11.0pt'><o:p> </o:p></span></p><div = style=3D'border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm = 4.0pt'><div><div style=3D'border:none;border-top:solid #B5C4DF = 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=3DMsoNormal><b><span lang=3DDE = style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span>= </b><span lang=3DDE = style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Glen = Fraser [mailto:[email protected]] <br><b>Sent:</b> Wednesday, August = 28, 2013 1:09 PM<br><b>To:</b> = [email protected]<br><b>Subject:</b> [luabind] How to = get Lua class name from C++ class?<o:p></o:p></span></p></div></div><p = class=3DMsoNormal><o:p> </o:p></p><p class=3DMsoNormal>Hello there, = I'm using luabind and trying to get the Lua subclass name from an = instance of the base class in C++.<o:p></o:p></p><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><p class=3DMsoNormal>I = want to use get_class_info(), but it expects an "argument" = rather than an "object". Perhaps there is a better way = to do this, besides trying to figure out how to convert a = luabind::object into a luabind::adl::argument=E2=80=A6 Here is = some example code that should illustrate the = problem:<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><div><div><p = class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#BB2CA2'>clas= s</span><span style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> = BaseClass {<o:p></o:p></span></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#BB2CA2'>publ= ic</span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:black'>:</spa= n><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#BB2CA2'><o:p= ></o:p></span></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> = <span style=3D'color:#BB2CA2'>virtual</span> ~BaseClass() = {}<o:p></o:p></span></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> = <span style=3D'color:#703DAA'>std</span>::<span = style=3D'color:#703DAA'>string</span> getClassName(<span = style=3D'color:#4F8187'>lua_State</span>* = L);<o:p></o:p></span></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:black'> = </span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#008400'>// = ... more stuff...<o:p></o:p></span></p></div><div><p = class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'>};<o:p></o:p></spa= n></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'><o:p> </o:p><= /span></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#BB2CA2'>clas= s</span><span style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> = BaseClass_wrapper : <span style=3D'color:#BB2CA2'>public</span> <span = style=3D'color:#4F8187'>BaseClass</span>, <span = style=3D'color:#BB2CA2'>public</span> <span = style=3D'color:#4F8187'>luabind</span>::<span = style=3D'color:#4F8187'>wrap_base</span> = {<o:p></o:p></span></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:black'> = </span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#008400'>// = ... some stuff...<o:p></o:p></span></p></div><div><p = class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'>};<o:p></o:p></spa= n></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'><o:p> </o:p><= /span></p></div><div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#703DAA'>std<= /span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'>::<span = style=3D'color:#703DAA'>string</span> <span = style=3D'color:#4F8187'>BaseClass</span>::getClassName(<span = style=3D'color:#4F8187'>lua_State</span>* = L)<o:p></o:p></span></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'>{<o:p></o:p></span= ></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:black'> = </span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#4F8187'>Base= Class_wrapper</span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:black'>* p = =3D </span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#BB2CA2'>dyna= mic_cast</span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:black'><</= span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#4F8187'>Base= Class_wrapper</span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:black'>*>(= </span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#BB2CA2'>this= </span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:black'>);</sp= an><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#4F8187'><o:p= ></o:p></span></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> = <span style=3D'color:#703DAA'>std</span>::<span = style=3D'color:#703DAA'>string</span> className(<span = style=3D'color:#D12F1B'>"UNKNOWN"</span>);<o:p></o:p></span></p= ></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> = <span style=3D'color:#BB2CA2'>if</span> (p !=3D <span = style=3D'color:#272AD8'>0</span>) {<o:p></o:p></span></p></div><div><p = class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> = luabind::object myObject(L, = p);<o:p></o:p></span></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#FF4013'>&nbs= p; luabind::class_info info =3D = luabind::get_class_info(myObject); // no good!</span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'><o:p></o:p></span>= </p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#FF4013'>&nbs= p; // no viable conversion from 'luabind::object' = to 'const luabind::adl::argument'</span><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'><o:p></o:p></span>= </p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> = className =3D = info.name;<o:p></o:p></span></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> = }<o:p></o:p></span></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> = <span style=3D'color:#BB2CA2'>return</span> = className;<o:p></o:p></span></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'>}<o:p></o:p></span= ></p></div><div><p class=3DMsoNormal><span = style=3D'font-size:10.5pt;font-family:"Menlo","serif"'><o:p> </o:p><= /span></p></div></div></div></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><p = class=3DMsoNormal>Thanks for any = suggestions,<o:p></o:p></p></div><div><p = class=3DMsoNormal>Glen.<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div></div></div></body></html> ------=_NextPart_000_0019_01CEA408.AA0CEAF0-- --===============2108133576143098204== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! Discover the easy way to master current and previous Microsoft technologies and advance your career. Get an incredible 1,500+ hours of step-by-step tutorial videos with LearnDevNow. Subscribe today and save! http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk --===============2108133576143098204== 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 --===============2108133576143098204==--