Re: How to get Lua class name from C++ class?
"Christian" <[email protected]> Wed, 28 Aug 2013 18:23:53 +0200
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
This is a multipart message in MIME format.
--===============5554592540490892409==
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0030_01CEA41B.C0DD6490"
Content-Language: de-at
This is a multipart message in MIME format.
------=_NextPart_000_0030_01CEA41B.C0DD6490
Content-Type: text/plain;
charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
You are right, argument has no constructor that takes a C++ object, =
sorry. But using push() and from_stack works, as in the following =
example (tested):
=20
#include <luabind/luabind.hpp>
#include <luabind/class_info.hpp>
=20
#include <iostream>
=20
class Foo {};
=20
int main()
{
lua_State* L =3D luaL_newstate();
luabind::open(L);
luabind::module(L) [
luabind::class_<Foo>("LuaFoo")
];
=20
Foo foo;
=20
luabind::object(L, &foo).push(L);
// Note: -1 instead of lua_gettop(L) would not work in the following =
line
// because of a bug in luabind::argument's ctor.
luabind::argument myArg(luabind::from_stack(L, lua_gettop(L)));
luabind::class_info info =3D luabind::get_class_info(myArg);
std::cout << info.name << '\n'; // Prints "LuaFoo".
}
=20
=20
From: Glen Fraser [mailto:[email protected]]=20
Sent: Wednesday, August 28, 2013 5:38 PM
To: [email protected]
Subject: Re: [luabind] How to get Lua class name from C++ class?
=20
Thanks, Christian, but I didn't manage to get anything to work in the =
way you describe. I can't seem to simply substitute 'object' with =
'argument'=E2=80=A6 I also tried using myObject.push(L), then using the =
"from_stack" referenced argument to call get_class_info(), then doing a =
lua_pop(), but that just crashes on me (a bit later on)=E2=80=A6and =
before that, it hasn't returned the correct class_info structure. I =
think I'd need to see a simple example, sorry.
=20
On the other hand, the "hacky" code from Eduard (see his earlier reply) =
does seem to work fine, as does another approach I came up with, where I =
just use luabind::call_function() to call the bound "class_info" =
function in Lua, then get the class_info structure by doing object_cast =
on the returned object. Of course, this may be (?) a bit less efficient =
than doing the direct stack-fiddling you guys suggest, but it works.
=20
Thanks,
Glen.
=20
On Aug 28, 2013, at 4:07 PM, "Christian" <[email protected]> wrote:
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:holaglen@ <http://gmail.com> gmail.com]=20
Sent: Wednesday, August 28, 2013 1:09 PM
To: <mailto:[email protected]> =
[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
-------------------------------------------------------------------------=
-----
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=3D58040911&iu=3D/4140/ostg=
.clktrk_______________________________________________> =
http://pubads.g.doubleclick.net/gampad/clk?id=3D58040911&iu=3D/4140/ostg.=
clktrk_______________________________________________
luabind-user mailing list
<mailto:[email protected]> =
[email protected]
<https://lists.sourceforge.net/lists/listinfo/luabind-user> =
https://lists.sourceforge.net/lists/listinfo/luabind-user
=20
------=_NextPart_000_0030_01CEA41B.C0DD6490
Content-Type: text/html;
charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<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 =
http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8"><meta =
name=3DGenerator content=3D"Microsoft Word 14 (filtered medium)"><base =
href=3D"x-msg://181/"><style><!--
/* Font Definitions */
@font-face
{font-family:Helvetica;
panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
{font-family:Helvetica;
panose-1:2 11 6 4 2 2 2 2 2 4;}
@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;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Sprechblasentext Zchn";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
span.E-MailFormatvorlage18
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.SprechblasentextZchn
{mso-style-name:"Sprechblasentext Zchn";
mso-style-priority:99;
mso-style-link:Sprechblasentext;
font-family:"Tahoma","sans-serif";}
span.sc91
{mso-style-name:sc91;
font-family:Consolas;
color:#804000;}
span.sc0
{mso-style-name:sc0;
font-family:Consolas;
color:black;}
span.sc161
{mso-style-name:sc161;
font-family:Consolas;
color:#8000FF;}
span.sc11
{mso-style-name:sc11;
font-family:Consolas;
color:black;}
span.sc101
{mso-style-name:sc101;
font-family:Consolas;
color:navy;
font-weight:bold;}
span.sc61
{mso-style-name:sc61;
font-family:Consolas;
color:gray;}
span.sc71
{mso-style-name:sc71;
font-family:Consolas;
color:gray;}
span.sc21
{mso-style-name:sc21;
font-family:Consolas;
color:green;}
.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;font-family:"Calibri","sans-serif"'>You are =
right, </span><span lang=3DEN-US =
style=3D'font-size:11.0pt;font-family:Consolas'>argument</span><span =
lang=3DEN-US =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif"'> has no =
constructor that takes a C++ object, sorry. But using </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;font-family:"Calibri","sans-serif"'> =
and</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;font-family:"Calibri","sans-serif"'> works, as =
in the following example (tested):<o:p></o:p></span></p><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p> =
</o:p></span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:#804000'>#include =
<luabind/luabind.hpp><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'background:white'><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:#804000'>#include =
<luabind/class_info.hpp><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'background:white'><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p> </=
o:p></span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:#804000'>#include =
<iostream><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'background:white'><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p> </=
o:p></span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:#8000FF'>class</span=
><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'> Foo =
</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>{};</span></b>=
<span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p> </=
o:p></span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:#8000FF'>int</span><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'> =
main</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>()</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'background:white'><b><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>{</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'> =
=C2=A0=C2=A0=C2=A0lua_State</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>*</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'> L =
</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>=3D</span></b>=
<span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'> =
luaL_newstate</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>();</span></b>=
<span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0 luabind</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>::</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>open</span><b=
><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>(</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>L</span><b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>);</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0 luabind</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>::</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>module</span>=
<b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>(</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>L</span><b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>)</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'> =
</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>[</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 luabind</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>::</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>class_</span>=
<b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'><</span></b=
><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>Foo</span><b>=
<span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>>(</span></=
b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:gray'>"LuaFoo&q=
uot;</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>)</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0 </span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>];</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0 <o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'background:white'><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0=C2=A0Foo foo</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>;</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0 <o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'background:white'><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0=C2=A0luabind</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>::</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>object</span>=
<b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>(</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>L</span><b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>,</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'> =
</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>&</span></=
b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>foo</span><b>=
<span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>).</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>push</span><b=
><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>(</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>L</span><b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>);</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0 </span><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:green'>// Note: -1 =
instead of lua_gettop(L) would not work in the following =
line<o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'background:white'><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0 </span><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:green'>// because =
of a bug in luabind::argument's ctor.<o:p></o:p></span></p><p =
class=3DMsoNormal style=3D'background:white'><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0 luabind</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>::</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>argument =
myArg</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>(</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>luabind</span=
><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>::</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>from_stack</s=
pan><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>(</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>L</span><b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>,</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'> =
lua_gettop</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>(</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>L</span><b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>)));</span></b=
><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0 luabind</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>::</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>class_info =
info </span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>=3D</span></b>=
<span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'> =
luabind</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>::</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>get_class_inf=
o</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>(</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>myArg</span><=
b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>);</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'background:white'><span =
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0 std</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>::</span></b><=
span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>cout =
</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'><<</span=
></b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'> =
info</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>.</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'>name =
</span><b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'><<</span=
></b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'> =
</span><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:gray'>'\n'</span><b>=
<span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>;</span></b><s=
pan lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'> =
</span><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Consolas;color:green'>// Prints =
"LuaFoo".<o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'background:white'><b><span =
style=3D'font-size:10.0pt;font-family:Consolas;color:navy'>}</span></b><s=
pan =
style=3D'font-size:10.0pt;font-family:Consolas;color:black'><o:p></o:p></=
span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p> =
</o:p></span></p><p class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif"'><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=3DEN-US =
style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span>=
</b><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Glen =
Fraser [mailto:[email protected]] <br><b>Sent:</b> Wednesday, August =
28, 2013 5:38 PM<br><b>To:</b> =
[email protected]<br><b>Subject:</b> Re: [luabind] How =
to get Lua class name from C++ =
class?<o:p></o:p></span></p></div></div><p class=3DMsoNormal><span =
lang=3DEN-US><o:p> </o:p></span></p><p class=3DMsoNormal>Thanks, =
Christian, but I didn't manage to get anything to work in the way you =
describe. I can't seem to simply substitute 'object' with =
'argument'=E2=80=A6 I also tried using myObject.push(L), then =
using the "from_stack" referenced argument to call =
get_class_info(), then doing a lua_pop(), but that just crashes on me (a =
bit later on)=E2=80=A6and before that, it hasn't returned the correct =
class_info structure. I think I'd need to see a simple example, =
sorry.<o:p></o:p></p><div><p =
class=3DMsoNormal><o:p> </o:p></p></div><div><p =
class=3DMsoNormal>On the other hand, the "hacky" code from =
Eduard (see his earlier reply) does seem to work fine, as does another =
approach I came up with, where I just use luabind::call_function() =
to call the bound "class_info" function in Lua, then get =
the class_info structure by doing object_cast on the returned object. =
Of course, this may be (?) a bit less efficient than doing the =
direct stack-fiddling you guys suggest, but it =
works.<o:p></o:p></p></div><div><p =
class=3DMsoNormal><o:p> </o:p></p></div><div><p =
class=3DMsoNormal>Thanks,<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><p class=3DMsoNormal>On =
Aug 28, 2013, at 4:07 PM, "Christian" <<a =
href=3D"mailto:[email protected]">[email protected]</a>> =
wrote:<o:p></o:p></p></div><p =
class=3DMsoNormal><br><br><o:p></o:p></p><div><div><p =
class=3DMsoNormal><span lang=3DEN-US style=3D'font-size:11.0pt'>Just =
replace</span><span class=3Dapple-converted-space><span lang=3DEN-US =
style=3D'font-size:11.0pt;font-family:Consolas'> </span></span><span=
lang=3DEN-US =
style=3D'font-size:11.0pt;font-family:Consolas'>luabind::object</span><sp=
an class=3Dapple-converted-space><span lang=3DEN-US =
style=3D'font-size:11.0pt'> </span></span><span lang=3DEN-US =
style=3D'font-size:11.0pt'>with<span =
class=3Dapple-converted-space> </span></span><span lang=3DEN-US =
style=3D'font-size:11.0pt;font-family:Consolas'>luabind::argument</span><=
span class=3Dapple-converted-space><span lang=3DEN-US =
style=3D'font-size:11.0pt'> </span></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.</span><o:p></o:p></p></div><div><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:11.0pt'> </span><o:p></o:p></p></div><div><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 =
class=3Dapple-converted-space> </span></span><span lang=3DEN-US =
style=3D'font-size:11.0pt;font-family:Consolas'>push()</span><span =
class=3Dapple-converted-space><span lang=3DEN-US =
style=3D'font-size:11.0pt'> </span></span><span lang=3DEN-US =
style=3D'font-size:11.0pt'>method and the others<span =
class=3Dapple-converted-space> </span></span><span lang=3DEN-US =
style=3D'font-size:11.0pt;font-family:Consolas'>from_stack</span><span =
class=3Dapple-converted-space><span lang=3DEN-US =
style=3D'font-size:11.0pt'> </span></span><span lang=3DEN-US =
style=3D'font-size:11.0pt'>constructor (but avoid relative indices =
with</span><span class=3Dapple-converted-space><span lang=3DEN-US =
style=3D'font-size:11.0pt;font-family:Consolas'> </span></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'>).</span><o:p></o:p></p></div><div><p =
class=3DMsoNormal><span lang=3DEN-US =
style=3D'font-size:11.0pt'> </span><o:p></o:p></p></div><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'><div><p class=3DMsoNormal><b><span =
lang=3DDE =
style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span>=
</b><span class=3Dapple-converted-space><span lang=3DDE =
style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'> </span=
></span><span lang=3DDE =
style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'>Glen Fraser =
[mailto:holaglen@<a href=3D"http://gmail.com"><span =
style=3D'color:purple'>gmail.com</span></a>]<span =
class=3Dapple-converted-space> </span><br><b>Sent:</b><span =
class=3Dapple-converted-space> </span>Wednesday, August 28, 2013 =
1:09 PM<br><b>To:</b><span class=3Dapple-converted-space> </span><a =
href=3D"mailto:[email protected]"><span =
style=3D'color:purple'>[email protected]</span></a><br><=
b>Subject:</b><span class=3Dapple-converted-space> </span>[luabind] =
How to get Lua class name from C++ =
class?</span><o:p></o:p></p></div></div></div><div><p =
class=3DMsoNormal> <o:p></o:p></p></div><div><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><div><div><p =
class=3DMsoNormal> <o:p></o:p></p></div></div><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><div><div><p =
class=3DMsoNormal> <o:p></o:p></p></div></div><div><div><div><p =
class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif";color:#BB2CA2'>clas=
s</span><span class=3Dapple-converted-space><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> </span></spa=
n><span style=3D'font-size:10.5pt;font-family:"Menlo","serif"'>BaseClass =
{</span><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'>publ=
ic</span><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'>:</span><o:p></o:p=
></p></div></div><div><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> =
<span class=3Dapple-converted-space> </span><span =
style=3D'color:#BB2CA2'>virtual</span><span =
class=3Dapple-converted-space> </span>~BaseClass() =
{}</span><o:p></o:p></p></div></div><div><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> =
<span class=3Dapple-converted-space> </span><span =
style=3D'color:#703DAA'>std</span>::<span =
style=3D'color:#703DAA'>string</span><span =
class=3Dapple-converted-space> </span>getClassName(<span =
style=3D'color:#4F8187'>lua_State</span>* =
L);</span><o:p></o:p></p></div></div><div><div><p =
class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> =
<span class=3Dapple-converted-space> </span><span =
style=3D'color:#008400'>// ... more =
stuff...</span></span><o:p></o:p></p></div></div><div><div><p =
class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'>};</span><o:p></o:=
p></p></div></div><div><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> </span><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 class=3Dapple-converted-space><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> </span></spa=
n><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'>BaseClass_wrapper =
:<span class=3Dapple-converted-space> </span><span =
style=3D'color:#BB2CA2'>public</span><span =
class=3Dapple-converted-space> </span><span =
style=3D'color:#4F8187'>BaseClass</span>,<span =
class=3Dapple-converted-space> </span><span =
style=3D'color:#BB2CA2'>public</span><span =
class=3Dapple-converted-space> </span><span =
style=3D'color:#4F8187'>luabind</span>::<span =
style=3D'color:#4F8187'>wrap_base</span><span =
class=3Dapple-converted-space> </span>{</span><o:p></o:p></p></div><=
/div><div><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> =
<span class=3Dapple-converted-space> </span><span =
style=3D'color:#008400'>// ... some =
stuff...</span></span><o:p></o:p></p></div></div><div><div><p =
class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'>};</span><o:p></o:=
p></p></div></div><div><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> </span><o:p>=
</o:p></p></div></div><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 =
class=3Dapple-converted-space> </span><span =
style=3D'color:#4F8187'>BaseClass</span>::getClassName(<span =
style=3D'color:#4F8187'>lua_State</span>* =
L)</span><o:p></o:p></p></div></div><div><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'>{</span><o:p></o:p=
></p></div></div><div><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> =
<span class=3Dapple-converted-space> </span><span =
style=3D'color:#4F8187'>BaseClass_wrapper</span>* p =3D<span =
class=3Dapple-converted-space> </span><span =
style=3D'color:#BB2CA2'>dynamic_cast</span><<span =
style=3D'color:#4F8187'>BaseClass_wrapper</span>*>(<span =
style=3D'color:#BB2CA2'>this</span>);</span><o:p></o:p></p></div></div><d=
iv><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> =
<span class=3Dapple-converted-space> </span><span =
style=3D'color:#703DAA'>std</span>::<span =
style=3D'color:#703DAA'>string</span><span =
class=3Dapple-converted-space> </span>className(<span =
style=3D'color:#D12F1B'>"UNKNOWN"</span>);</span><o:p></o:p></p=
></div></div><div><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> =
<span class=3Dapple-converted-space> </span><span =
style=3D'color:#BB2CA2'>if</span><span =
class=3Dapple-converted-space> </span>(p !=3D<span =
class=3Dapple-converted-space> </span><span =
style=3D'color:#272AD8'>0</span>) =
{</span><o:p></o:p></p></div></div><div><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> =
luabind::object myObject(L, =
p);</span><o:p></o:p></p></div></div><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><o:p></o:p></p></div></div><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><o:p></o:p></p></div></div><div><div><p =
class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> =
className =3D =
info.name;</span><o:p></o:p></p></div></div><div><div><p =
class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> =
}</span><o:p></o:p></p></div></div><div><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> =
<span class=3Dapple-converted-space> </span><span =
style=3D'color:#BB2CA2'>return</span><span =
class=3Dapple-converted-space> </span>className;</span><o:p></o:p></=
p></div></div><div><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'>}</span><o:p></o:p=
></p></div></div><div><div><p class=3DMsoNormal><span =
style=3D'font-size:10.5pt;font-family:"Menlo","serif"'> </span><o:p>=
</o:p></p></div></div></div></div><div><div><p =
class=3DMsoNormal> <o:p></o:p></p></div></div><div><div><p =
class=3DMsoNormal>Thanks for any =
suggestions,<o:p></o:p></p></div></div><div><div><p =
class=3DMsoNormal>Glen.<o:p></o:p></p></div></div><div><div><p =
class=3DMsoNormal> <o:p></o:p></p></div></div></div><p =
class=3DMsoNormal><span =
style=3D'font-size:13.5pt;font-family:"Helvetica","sans-serif"'>---------=
---------------------------------------------------------------------<br>=
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, =
more!<br>Discover the easy way to master current and previous Microsoft =
technologies<br>and advance your career. Get an incredible 1,500+ hours =
of step-by-step<br>tutorial videos with LearnDevNow. Subscribe today and =
save!<br><a =
href=3D"http://pubads.g.doubleclick.net/gampad/clk?id=3D58040911&iu=3D=
/4140/ostg.clktrk_______________________________________________"><span =
style=3D'color:purple'>http://pubads.g.doubleclick.net/gampad/clk?id=3D58=
040911&iu=3D/4140/ostg.clktrk________________________________________=
_______</span></a><br>luabind-user mailing list<br><a =
href=3D"mailto:[email protected]"><span =
style=3D'color:purple'>[email protected]</span></a><br><=
a =
href=3D"https://lists.sourceforge.net/lists/listinfo/luabind-user"><span =
style=3D'color:purple'>https://lists.sourceforge.net/lists/listinfo/luabi=
nd-user</span></a><o:p></o:p></span></p></div></div><p =
class=3DMsoNormal><o:p> </o:p></p></div></div></div></body></html>
------=_NextPart_000_0030_01CEA41B.C0DD6490--
--===============5554592540490892409==
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
--===============5554592540490892409==
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
--===============5554592540490892409==--