How to get Lua class name from C++ class?
Glen Fraser <[email protected]> Wed, 28 Aug 2013 13:09:24 +0200
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
--===============6134894840989656782==
Content-Type: multipart/alternative;
boundary="Apple-Mail=_0883A61E-228D-45D1-844E-A206D517AAEB"
--Apple-Mail=_0883A61E-228D-45D1-844E-A206D517AAEB
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=windows-1252
Hello there, I'm using luabind and trying to get the Lua subclass name =
from an instance of the base class in C++.
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=85 Here is some example code that should =
illustrate the problem:
class BaseClass {
public:
virtual ~BaseClass() {}
std::string getClassName(lua_State* L);
// ... more stuff...
};
class BaseClass_wrapper : public BaseClass, public luabind::wrap_base {
// ... some stuff...
};
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;
}
Thanks for any suggestions,
Glen.
--Apple-Mail=_0883A61E-228D-45D1-844E-A206D517AAEB
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; ">Hello =
there, I'm using luabind and trying to get the Lua subclass name from an =
instance of the base class in C++.<div><br></div><div>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=85 =
Here is some example code that should illustrate the =
problem:</div><div><br></div><div><div style=3D"margin: 0px; font-size: =
14px; font-family: Menlo; "><div style=3D"margin: 0px; "><span =
style=3D"color: #bb2ca2">class</span> BaseClass {</div><div =
style=3D"margin: 0px; color: rgb(187, 44, 162); ">public<span =
style=3D"color: #000000">:</span></div><div style=3D"margin: 0px; =
"> <span style=3D"color: #bb2ca2">virtual</span> =
~BaseClass() {}</div><div style=3D"margin: 0px; "> <span =
style=3D"color: #703daa">std</span>::<span style=3D"color: =
#703daa">string</span> getClassName(<span style=3D"color: =
#4f8187">lua_State</span>* L);</div><div style=3D"margin: 0px; color: =
rgb(0, 132, 0); "><span style=3D"color: #000000"> </span>// =
... more stuff...</div><div style=3D"margin: 0px; ">};</div><div =
style=3D"margin: 0px; min-height: 16px; "><br></div><div style=3D"margin: =
0px; "><span style=3D"color: #bb2ca2">class</span> 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> {</div><div style=3D"margin: 0px; color: =
rgb(0, 132, 0); "><span style=3D"color: #000000"> </span>// =
... some stuff...</div><div style=3D"margin: 0px; ">};</div><div =
style=3D"margin: 0px; min-height: 16px; "><br></div><div style=3D"margin: =
0px; "><div style=3D"margin: 0px; "><span style=3D"color: =
#703daa">std</span>::<span style=3D"color: #703daa">string</span> <span =
style=3D"color: #4f8187">BaseClass</span>::getClassName(<span =
style=3D"color: #4f8187">lua_State</span>* L)</div><div style=3D"margin: =
0px; ">{</div><div style=3D"margin: 0px; color: rgb(79, 129, 135); =
"><span style=3D"color: #000000"> =
</span>BaseClass_wrapper<span style=3D"color: #000000">* p =3D =
</span><span style=3D"color: #bb2ca2">dynamic_cast</span><span =
style=3D"color: #000000"><</span>BaseClass_wrapper<span style=3D"color:=
#000000">*>(</span><span style=3D"color: #bb2ca2">this</span><span =
style=3D"color: #000000">);</span></div><div style=3D"margin: 0px; =
"> <span style=3D"color: #703daa">std</span>::<span =
style=3D"color: #703daa">string</span> className(<span style=3D"color: =
#d12f1b">"UNKNOWN"</span>);</div><div style=3D"margin: 0px; "> =
<span style=3D"color: #bb2ca2">if</span> (p !=3D <span =
style=3D"color: #272ad8">0</span>) {</div><div style=3D"margin: 0px; =
"> luabind::object myObject(L, p);</div><div =
style=3D"margin: 0px; "><font color=3D"#ff4013"> =
luabind::class_info info =3D luabind::get_class_info(myObject); =
// no good!</font></div><div style=3D"margin: 0px; "><font =
color=3D"#ff4013"> // no viable conversion =
from 'luabind::object' to 'const =
luabind::adl::argument'</font></div><div style=3D"margin: 0px; "> =
className =3D info.name;</div><div style=3D"margin: =
0px; "> }</div><div style=3D"margin: 0px; "> =
<span style=3D"color: #bb2ca2">return</span> className;</div><div =
style=3D"margin: 0px; =
">}</div><div><br></div></div></div></div><div><br></div><div>Thanks for =
any suggestions,</div><div>Glen.</div><div><br></div></body></html>=
--Apple-Mail=_0883A61E-228D-45D1-844E-A206D517AAEB--
--===============6134894840989656782==
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
--===============6134894840989656782==
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
--===============6134894840989656782==--