Re: How to get Lua class name from C++ class?
Glen Fraser <[email protected]> Wed, 28 Aug 2013 23:24:15 +0200
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
--===============2677303095912198154==
Content-Type: multipart/alternative;
boundary="Apple-Mail=_C90F124C-625C-45CC-962A-E0093E6D66D0"
--Apple-Mail=_C90F124C-625C-45CC-962A-E0093E6D66D0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=windows-1252
Okay, thanks, that works. I also need to do a pop afterwards, or the =
stack keeps growing, right? (Seems to be the case, judging by printing =
out lua_gettop(L) before and after the method.)
> 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);
::lua_pop(L, 1);
Great, thanks -- I guess my problems were because of that bug you =
mention, because I was using -1 in luabind::argument's ctor. Didn't =
know there was any problem with that.
Glen.
On Aug 28, 2013, at 6:23 PM, Christian <[email protected]> wrote:
> You are right, argument has no constructor that takes a C++ object, =
sorry. But using push() and from_stackworks, 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'=85 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)=85and 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
--Apple-Mail=_C90F124C-625C-45CC-962A-E0093E6D66D0
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"><base href=3D"x-msg://181/"></head><body =
style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; =
-webkit-line-break: after-white-space; ">Okay, thanks, that works. =
I also need to do a pop afterwards, or the stack keeps growing, =
right? (Seems to be the case, judging by printing out lua_gettop(L) =
before and after the =
method.)<div><br></div><div><br></div><div><blockquote type=3D"cite"><div =
lang=3D"DE-AT" link=3D"blue" vlink=3D"purple"><div class=3D"WordSection1" =
style=3D"page: WordSection1; "><div style=3D"margin: 0cm 0cm 0.0001pt; =
font-size: 12pt; font-family: 'Times New Roman', serif; =
background-color: white; "><span lang=3D"EN-US" style=3D"font-size: =
10pt; font-family: Consolas; "> luabind</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">::</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">object</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">L</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">,</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "> </span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">&</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">foo</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">).</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">push</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">L</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">);</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; "> </span><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
green; ">// Note: -1 instead of lua_gettop(L) would not work in the =
following line<o:p></o:p></span></div><div style=3D"margin: 0cm 0cm =
0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; =
background-color: white; "><span lang=3D"EN-US" style=3D"font-size: =
10pt; font-family: Consolas; "> </span><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
green; ">// because of a bug in luabind::argument's =
ctor.<o:p></o:p></span></div><div style=3D"margin: 0cm 0cm 0.0001pt; =
font-size: 12pt; font-family: 'Times New Roman', serif; =
background-color: white; "><span lang=3D"EN-US" style=3D"font-size: =
10pt; font-family: Consolas; "> luabind</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">::</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">argument myArg</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">luabind</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">::</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">from_stack</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">L</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">,</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "> lua_gettop</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">L</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">)));</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; "> =
luabind</span><b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; color: navy; ">::</span></b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; ">class_info =
info </span><b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; color: navy; ">=3D</span></b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; =
"> luabind</span><b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; color: navy; ">::</span></b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; =
">get_class_info</span><b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; color: navy; ">(</span></b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; ">myArg</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; =
">);</span></b></div></div></div></blockquote></div><div><br></div><div><f=
ont face=3D"Monaco"> ::lua_pop(L, =
1);</font></div><div><br></div><div>Great, thanks -- I guess my problems =
were because of that bug you mention, because I was using -1 in =
luabind::argument's ctor. Didn't know there was any problem with =
that.</div><div><br></div><div>Glen.</div><div><br></div><div><div>On =
Aug 28, 2013, at 6:23 PM, Christian <<a =
href=3D"mailto:[email protected]">[email protected]</a>> wrote:</div><br =
class=3D"Apple-interchange-newline"><blockquote type=3D"cite"><div =
lang=3D"DE-AT" link=3D"blue" vlink=3D"purple" style=3D"font-family: =
Helvetica; font-size: medium; font-style: normal; font-variant: normal; =
font-weight: normal; letter-spacing: normal; line-height: normal; =
orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: =
none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div =
class=3D"WordSection1" style=3D"page: WordSection1; "><div =
style=3D"margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times =
New Roman', serif; "><span lang=3D"EN-US" style=3D"font-size: 11pt; =
font-family: Calibri, sans-serif; ">You are right,<span =
class=3D"Apple-converted-space"> </span></span><span lang=3D"EN-US" =
style=3D"font-size: 11pt; font-family: Consolas; ">argument</span><span =
lang=3D"EN-US" style=3D"font-size: 11pt; font-family: Calibri, =
sans-serif; "><span class=3D"Apple-converted-space"> </span>has no =
constructor that takes a C++ object, sorry. But using<span =
class=3D"Apple-converted-space"> </span></span><span lang=3D"EN-US" =
style=3D"font-size: 11pt; font-family: Consolas; ">push()</span><span =
lang=3D"EN-US" style=3D"font-size: 11pt; font-family: Calibri, =
sans-serif; "><span =
class=3D"Apple-converted-space"> </span>and</span><span =
lang=3D"EN-US" style=3D"font-size: 11pt; font-family: Consolas; "><span =
class=3D"Apple-converted-space"> </span>from_stack</span><span =
lang=3D"EN-US" style=3D"font-size: 11pt; font-family: Calibri, =
sans-serif; ">works, as in the following example =
(tested):<o:p></o:p></span></div><div style=3D"margin: 0cm 0cm 0.0001pt; =
font-size: 12pt; font-family: 'Times New Roman', serif; "><span =
lang=3D"EN-US" style=3D"font-size: 11pt; font-family: Calibri, =
sans-serif; "> </span></div><div style=3D"margin: 0cm 0cm 0.0001pt; =
font-size: 12pt; font-family: 'Times New Roman', serif; =
background-color: white; "><span lang=3D"EN-US" style=3D"font-size: =
10pt; font-family: Consolas; color: rgb(128, 64, 0); ">#include =
<luabind/luabind.hpp><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; color: rgb(128, 64, 0); ">#include =
<luabind/class_info.hpp><o:p></o:p></span></div><div =
style=3D"margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times =
New Roman', serif; background-color: white; "><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; =
"> </span></div><div style=3D"margin: 0cm 0cm 0.0001pt; font-size: =
12pt; font-family: 'Times New Roman', serif; background-color: white; =
"><span lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; =
color: rgb(128, 64, 0); ">#include =
<iostream><o:p></o:p></span></div><div style=3D"margin: 0cm 0cm =
0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; =
background-color: white; "><span lang=3D"EN-US" style=3D"font-size: =
10pt; font-family: Consolas; "> </span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; color: rgb(128, 0, 255); =
">class</span><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><span =
class=3D"Apple-converted-space"> </span>Foo<span =
class=3D"Apple-converted-space"> </span></span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">{};</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; "> </span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; color: rgb(128, 0, 255); ">int</span><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; "><span =
class=3D"Apple-converted-space"> </span>main</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">()</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">{</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; =
"> lua_State</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">*</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><span =
class=3D"Apple-converted-space"> </span>L<span =
class=3D"Apple-converted-space"> </span></span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">=3D</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><span =
class=3D"Apple-converted-space"> </span>luaL_newstate</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">();</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; "> =
luabind</span><b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; color: navy; ">::</span></b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; ">open</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">L</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">);</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; "> =
luabind</span><b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; color: navy; ">::</span></b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; ">module</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">L</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">)</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "> </span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">[</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; =
"> luabind</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">::</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">class_</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
"><</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">Foo</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">>(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; color: gray; ">"LuaFoo"</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">)</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; "> <span =
class=3D"Apple-converted-space"> </span></span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">];</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; =
"> <o:p></o:p></span></div><div style=3D"margin: 0cm =
0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; =
background-color: white; "><span lang=3D"EN-US" style=3D"font-size: =
10pt; font-family: Consolas; "> Foo =
foo</span><b><span lang=3D"EN-US" style=3D"font-size: 10pt; font-family: =
Consolas; color: navy; ">;</span></b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; =
"><o:p></o:p></span></div><div style=3D"margin: 0cm 0cm 0.0001pt; =
font-size: 12pt; font-family: 'Times New Roman', serif; =
background-color: white; "><span lang=3D"EN-US" style=3D"font-size: =
10pt; font-family: Consolas; =
"> <o:p></o:p></span></div><div style=3D"margin: 0cm =
0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; =
background-color: white; "><span lang=3D"EN-US" style=3D"font-size: =
10pt; font-family: Consolas; =
"> luabind</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">::</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">object</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">L</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">,</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "> </span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">&</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">foo</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">).</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">push</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">L</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">);</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; "> <span =
class=3D"Apple-converted-space"> </span></span><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: green; ">// =
Note: -1 instead of lua_gettop(L) would not work in the following =
line<o:p></o:p></span></div><div style=3D"margin: 0cm 0cm 0.0001pt; =
font-size: 12pt; font-family: 'Times New Roman', serif; =
background-color: white; "><span lang=3D"EN-US" style=3D"font-size: =
10pt; font-family: Consolas; "> <span =
class=3D"Apple-converted-space"> </span></span><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: green; ">// =
because of a bug in luabind::argument's =
ctor.<o:p></o:p></span></div><div style=3D"margin: 0cm 0cm 0.0001pt; =
font-size: 12pt; font-family: 'Times New Roman', serif; =
background-color: white; "><span lang=3D"EN-US" style=3D"font-size: =
10pt; font-family: Consolas; "> luabind</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">::</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">argument myArg</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">luabind</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">::</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">from_stack</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">L</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">,</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><span =
class=3D"Apple-converted-space"> </span>lua_gettop</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">L</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">)));</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; "> =
luabind</span><b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; color: navy; ">::</span></b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; ">class_info info<span =
class=3D"Apple-converted-space"> </span></span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">=3D</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><span =
class=3D"Apple-converted-space"> </span>luabind</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">::</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">get_class_info</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">(</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">myArg</span><b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: navy; =
">);</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; "><o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><span lang=3D"EN-US" style=3D"font-size:=
10pt; font-family: Consolas; "> std</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">::</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">cout<span =
class=3D"Apple-converted-space"> </span></span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; "><<</span></b><span lang=3D"EN-US" style=3D"font-size: =
10pt; font-family: Consolas; "><span =
class=3D"Apple-converted-space"> </span>info</span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; ">.</span></b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; ">name<span =
class=3D"Apple-converted-space"> </span></span><b><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
navy; "><<</span></b><span lang=3D"EN-US" style=3D"font-size: =
10pt; font-family: Consolas; "> </span><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; color: gray; =
">'\n'</span><b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Consolas; color: navy; ">;</span></b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Consolas; "> </span><span =
lang=3D"EN-US" style=3D"font-size: 10pt; font-family: Consolas; color: =
green; ">// Prints "LuaFoo".<o:p></o:p></span></div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; background-color: white; "><b><span style=3D"font-size: 10pt; =
font-family: Consolas; color: navy; ">}</span></b><span =
style=3D"font-size: 10pt; font-family: Consolas; =
"><o:p></o:p></span></div><div style=3D"margin: 0cm 0cm 0.0001pt; =
font-size: 12pt; font-family: 'Times New Roman', serif; "><span =
lang=3D"EN-US" style=3D"font-size: 11pt; font-family: Calibri, =
sans-serif; "> </span></div><div style=3D"margin: 0cm 0cm 0.0001pt; =
font-size: 12pt; font-family: 'Times New Roman', serif; "><span =
lang=3D"EN-US" style=3D"font-size: 11pt; font-family: Calibri, =
sans-serif; "> </span></div><div style=3D"border-style: none none =
none solid; border-left-width: 1.5pt; border-left-color: blue; padding: =
0cm 0cm 0cm 4pt; position: static; z-index: auto; "><div><div =
style=3D"border-style: solid none none; border-top-width: 1pt; =
border-top-color: rgb(181, 196, 223); padding: 3pt 0cm 0cm; "><div =
style=3D"margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times =
New Roman', serif; "><b><span lang=3D"EN-US" style=3D"font-size: 10pt; =
font-family: Tahoma, sans-serif; ">From:</span></b><span lang=3D"EN-US" =
style=3D"font-size: 10pt; font-family: Tahoma, sans-serif; "><span =
class=3D"Apple-converted-space"> </span>Glen Fraser =
[mailto:holaglen@<a href=3D"http://gmail.com" style=3D"color: purple; =
text-decoration: underline; ">gmail.com</a>]<span =
class=3D"Apple-converted-space"> </span><br><b>Sent:</b><span =
class=3D"Apple-converted-space"> </span>Wednesday, August 28, 2013 =
5:38 PM<br><b>To:</b><span class=3D"Apple-converted-space"> </span><a=
href=3D"mailto:[email protected]" style=3D"color: =
purple; text-decoration: underline; =
">[email protected]</a><br><b>Subject:</b><span =
class=3D"Apple-converted-space"> </span>Re: [luabind] How to get =
Lua class name from C++ class?<o:p></o:p></span></div></div></div><div =
style=3D"margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times =
New Roman', serif; "><span lang=3D"EN-US"> </span></div><div =
style=3D"margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times =
New Roman', serif; ">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'=85 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)=85and 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></div><div><div style=3D"margin: 0cm 0cm 0.0001pt; =
font-size: 12pt; font-family: 'Times New Roman', serif; =
"><o:p> </o:p></div></div><div><div style=3D"margin: 0cm 0cm =
0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">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></div></div><div><div style=3D"margin: =
0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; "><o:p> </o:p></div></div><div><div style=3D"margin: 0cm 0cm =
0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; =
">Thanks,<o:p></o:p></div></div><div><div style=3D"margin: 0cm 0cm =
0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; =
">Glen.<o:p></o:p></div></div><div><div style=3D"margin: 0cm 0cm =
0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; =
"><o:p> </o:p></div></div></div></div></div></blockquote></div></body=
></html>=
--Apple-Mail=_C90F124C-625C-45CC-962A-E0093E6D66D0--
--===============2677303095912198154==
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
--===============2677303095912198154==
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
--===============2677303095912198154==--