class method binding problem

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

class method binding problem

deshanc
Hi

I am writing a lib with lua bind. I have stucked in problem for the entire day. Please shed some light.
Following is the class that I need to bind to lua.


class SoundManager
{
public:
 bool init(const std::string &deviceName = "",  unsigned int sources = 100, Ogre::SceneManager* sMan=0);
 ...
};
And this is what I have done for luabind
luabind::module(luaState)
[

 luabind::class_<SoundManager>("SoundManager")

 .def(luabind::constructor<>())
 .def("init", &SoundManager::init) 
 ...
];

Since I have Ogre::SceneManager as a parameter in init() method, I guess I have to bind the Ogre::SceneManager class too.
So I did the following.
luabind::module(luaState)
[

 luabind::class_<SceneManager>("SceneManager "

];
And this is my lua code which gives a lua runtime error. It throws from luabind\detail\call_function.hpp at operator Ret().
Please note that i am getting the error when I call the init() function.
When init function is commented it works fine.

soundManager = SoundManager.getSingletonPtr();

function Manager_getSoundManager()
	soundManager:setDistanceModel(AL_LINEAR_DISTANCE);
	--soundManager:init();
	return soundManager;
end

Please help me with this
~deshan


------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: class method binding problem

Nigel Atkinson-2
Ah, another Ogre3d user I see.  I've just been playing with Ogre
myself...
Anyhow.

It's a bit hard to tell, perhaps you could copy & paste the error
message?  Also is the space at the end of "SceneManager" in your binding
a typo or in your code?

Nigel (merlinblack on the Ogre3d forums)

On Wed, 2010-12-08 at 11:57 +0530, chamika deshan wrote:

> Hi
>
> I am writing a lib with lua bind. I have stucked in problem for the
> entire day. Please shed some light.
> Following is the class that I need to bind to lua.
>
>
>
> class SoundManager
> {
> public:
>  bool init(const std::string &deviceName = "",  unsigned int sources = 100, Ogre::SceneManager* sMan=0);
> ...
> };
> And this is what I have done for luabind
> luabind::module(luaState)
> [
>
>
>  luabind::class_<SoundManager>("SoundManager")
>
>
>  .def(luabind::constructor<>())
>  .def("init", &SoundManager::init)
>
>
>  ...
> ];
>
>
> Since I have Ogre::SceneManager as a parameter in init() method, I guess I have to bind the Ogre::SceneManager class too.
>
>
> So I did the following.
>
>
> luabind::module(luaState)
> [
>
>
>  luabind::class_<SceneManager>("SceneManager ")
>
>
> ];
> And this is my lua code which gives a lua runtime error. It throws from luabind\detail\call_function.hpp at operator Ret().
>
>
> Please note that i am getting the error when I call the init() function.
>
>
> When init function is commented it works fine.
>
>
> soundManager = SoundManager.getSingletonPtr();
>
> function Manager_getSoundManager()
> soundManager:setDistanceModel(AL_LINEAR_DISTANCE);
> --soundManager:init();
> return soundManager;
> end
>
> Please help me with this
> ~deshan
>
>
>
> ------------------------------------------------------------------------------
> What happens now with your Lotus Notes apps - do you make another costly
> upgrade, or settle for being marooned without product support? Time to move
> off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
> use, and manage than apps on traditional platforms. Sign up for the Lotus
> Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
> _______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user



------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: class method binding problem

deshanc
Thank you very much for the reply.
Nice to here that there are many ogre3d users around.

The error is a lua run time error. That is what i get when prints the error.

I have identified the problem. 
Here I have to provide parameters for the init method. It does not take default parameters.

It took my around 1 and half day to find that. 

On Wed, Dec 8, 2010 at 12:26 PM, Nigel Atkinson <[hidden email]> wrote:
Ah, another Ogre3d user I see.  I've just been playing with Ogre
myself...
Anyhow.

It's a bit hard to tell, perhaps you could copy & paste the error
message?  Also is the space at the end of "SceneManager" in your binding
a typo or in your code?

Nigel (merlinblack on the Ogre3d forums)

On Wed, 2010-12-08 at 11:57 +0530, chamika deshan wrote:
> Hi
>
> I am writing a lib with lua bind. I have stucked in problem for the
> entire day. Please shed some light.
> Following is the class that I need to bind to lua.
>
>
>
> class SoundManager
> {
> public:
>  bool init(const std::string &deviceName = "",  unsigned int sources = 100, Ogre::SceneManager* sMan=0);
> ...
> };
> And this is what I have done for luabind
> luabind::module(luaState)
> [
>
>
>  luabind::class_<SoundManager>("SoundManager")
>
>
>  .def(luabind::constructor<>())
>  .def("init", &SoundManager::init)
>
>
>  ...
> ];
>
>
> Since I have Ogre::SceneManager as a parameter in init() method, I guess I have to bind the Ogre::SceneManager class too.
>
>
> So I did the following.
>
>
> luabind::module(luaState)
> [
>
>
>  luabind::class_<SceneManager>("SceneManager ")
>
>
> ];
> And this is my lua code which gives a lua runtime error. It throws from luabind\detail\call_function.hpp at operator Ret().
>
>
> Please note that i am getting the error when I call the init() function.
>
>
> When init function is commented it works fine.
>
>
> soundManager = SoundManager.getSingletonPtr();
>
> function Manager_getSoundManager()
>       soundManager:setDistanceModel(AL_LINEAR_DISTANCE);
>       --soundManager:init();
>       return soundManager;
> end
>
> Please help me with this
> ~deshan
>
>
>
> ------------------------------------------------------------------------------
> What happens now with your Lotus Notes apps - do you make another costly
> upgrade, or settle for being marooned without product support? Time to move
> off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
> use, and manage than apps on traditional platforms. Sign up for the Lotus
> Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
> _______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user



------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: class method binding problem

Nigel Atkinson-2
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: class method binding problem

Teto
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 <[hidden email]> 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
> [hidden email]
> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user