Re: class method binding problem
Teto <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
or you can explicitly register the different methods:
For example in my code, I have only one method with parameters having
default values:
If I do that:
def("addSpeech",(void (CDialogState::*)(CSpeaker*,const std::string&
,const std::string&))&CDialogState::AddSpeech)
.def("addSpeech",(void (CDialogState::*)(CSpeaker*,const
std::string&)) &CDialogState::AddSpeech)
lua will correctly call the function, supplying missing parameters.
On Wed, Dec 8, 2010 at 11:19 PM, Nigel Atkinson <[email protected]> wrote:
>
> Ah, right. I ran into that problem too with binding various ogre classes and methods.
>
> What I tended to do, if I did not want to have to give all the parameters in Lua scripts, was make a "proxy" function, and bind that as one of the class methods. For example something like:
>
> void SceneNode_yaw( SceneNode* self, Radian angle )
> {
> self->yaw( angle );
> }
>
> ....
>
> module(L)
> [
> class_<SceneNode>("SceneNode")
> .....
> .def("yaw", &SceneNode_yaw )
> ....
> ];
>
> This works as Luabind passes a this pointer which in this case lands in "self" rather than the hidden "this" parameter of a normal class method.
>
> Or another way is to override the function in Lua, and use its optional arg functionality:
>
> old_yaw = SceneNode.yaw
> function SceneNode:yaw( angle, transformspace )
> if transformspace == nil then
> transformspace = SceneNode.TS_LOCAL
> end
>
> old_yaw( angle, transformspace )
> end
>
> Have a look at: https://github.com/merlinblack/Game-Engine-Testbed/blob/level1/src/luabinding.cpp
>
> Feel free to grab anything that looks useful to you!
>
> Nigel Atkinson
> ------------------------------------------------------------------------------
> This SF Dev2Dev email is sponsored by:
>
> WikiLeaks The End of the Free Internet
> http://p.sf.net/sfu/therealnews-com
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
------------------------------------------------------------------------------
This SF Dev2Dev email is sponsored by:
WikiLeaks The End of the Free Internet
http://p.sf.net/sfu/therealnews-com
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user