Re: Problem with derived classes and overloaded member functions
Nigel Atkinson <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <1269307116.3546.6.camel@hurin> |
How are you calling the 'help' function in Lua?
Remember that:
classInstance:method( param )
is just syntactic sugar for
classInstance.method( classInstance, param )
so in your case if you called help as
instance.help()
it will not match any of your bound functions, as the 'self' argument is
not given. I personally see this all the time, as I have a Lua based
console in the game I'm writing, and I often misstype '.' where I should
have written ":"
Nigel
On Mon, 2010-03-22 at 20:39 +0100, Saner Daniel wrote:
> Hello,
>
> I have previously posted this with an unregistered e-Mail, but the message was never approved, so excuse me if it will appears again one day...
> I'm very new to both Lua and luabind. I have a problem and I'm not sure whether I'm doing something wrong in handling an overloaded member function, or the derived class in which they are defined. I have used luabind with overloaded functions before, and I've used it with derived classes before, both without problem, but now that I tried combining the two, I am oscillating between compilation errors and runtime errors.
>
> My base class is called 'IStreamPlugin' and has an overloaded member function called 'help', one of them taking no arguments and another one taking a 'const char *'. A derived class called 'PluginCLGeneric' implements these two functions. The way I tried to register them using 'luabind' is:
>
> luabind::module(L) [
> luabind::class_<PluginCLGeneric>("PluginCLGeneric")
> .def(luabind::constructor<StreamManager&, LogManager&, lua_State*>())
> .def("help", (void(PluginCLGeneric::*)())&PluginCLGeneric::help)
> .def("help", (void(PluginCLGeneric::*)(const char*))&PluginCLGeneric::help)
> ];
>
> This compiles fine, but when trying to call either of the 'help' functions from Lua, I get this error:
>
> No matching overload found, candidates:
> void help(PluginCLGeneric&,char const*)
> void help(PluginCLGeneric&)
>
> I figured that the problem might stem from the fact that I export only the derived class to Lua, and not the respective base class (although the exported functions do not depend on anything that stems from the base class). I rewrote my luabind section like this:
>
> luabind::module(L) [
> luabind::class_<IStreamPlugin>("IStreamPlugin"),
> luabind::class_<PluginCLGeneric, IStreamPlugin>("PluginCLGeneric")
> .def(luabind::constructor<StreamManager&, LogManager&, lua_State*>())
> .def("help", (void(PluginCLGeneric::*)())&PluginCLGeneric::help)
> .def("help", (void(PluginCLGeneric::*)(const char*))&PluginCLGeneric::help)
> ];
>
> according to the luabind documentation. However, this yields the following compilation error:
>
> luabind/detail/inheritance.hpp(136) : error C2243: 'static_cast' : conversion from 'PluginCLGeneric *' to 'bases_t *' exists, but is inaccessible
>
> I tried also exporting the constructor and the base class' versions of the functions (although they are pure virtual) with the same results. Also, if I change the second 'luabind::class' line to incorporate 'bases', i.e.
>
> luabind::class_<PluginCLGeneric, luabind::bases<IStreamPlugin>>("PluginCLGeneric")
>
> the error message changes to:
>
> luabind/detail/inheritance.hpp(136) : error C2243: 'static_cast' : conversion from 'PluginCLGeneric *' to 'IStreamPlugin *' exists, but is inaccessible
>
> I am a bit at a loss what it means that this cast is supposed to be inaccessible, or even needed. Can someone point me in the right direction?
>
> I am using Visual C++ 2008 and a statically linked luabind-0.9.
>
> Cheers
> Daniel
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev