Sign in to follow this  
deshan

LuaBind help need

Recommended Posts

Hi

This is my first post in game dev.

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 = "", 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 SceneManager as a parameter in init() method, do I have to bind the SceneManager class too?
If yes, does the following enough?


luabind::module(luaState)
[
luabind::class_<SceneManager >("SceneManager ")
];



And this is my lua code which gives an error.


soundManager = SoundManager();

function getSoundManager()
soundManager:setDistanceModel(AL_LINEAR_DISTANCE);
soundManager:init(); -- when comment this line function call works fine
return soundManager;
end



Please help me,

Thank you

[Edited by - deshan on December 7, 2010 11:04:24 PM]

Share this post


Link to post
Share on other sites
Quote:
Since I have SceneManager as a parameter in init() method, do I have to bind the SceneManager class too?
If yes, does the following enough?

If my memory servers me correctly yes.

Quote:
And this is my lua code which gives an error.

It is always a good idea to post the actual error which you are seeing, I would imagine it complains about not being able to find a matching function or words to that effect. The problem is due to init using default values which Luabind does not currently support( scheduled for 1.0 release IIRC). The recommended method to get this working at the moment is to provide three wrapper function which the following signatures.

bool init0(SoundManager& self);
bool init1(SoundManager& self,const std::string &deviceName);
bool init2(SoundManager& self,const std::string &deviceName, SceneManager* sMan);


Where the functions just pass the parameters, if any, to the real function calling it on the object "self".

Share this post


Link to post
Share on other sites
Hello dmail,

Thank you very much for the reply.

Quote:

If my memory servers me correctly yes.

so I kept the code

luabind::module(luaState)
[
luabind::class_<Ogre::SceneManager>( "SceneManager" )
];





Quote:
It is always a good idea to post the actual error which you are seeing,


I am sorry, It is a lua runtime error. It throws from luabind\detail\call_function.hpp at operator Ret()

operator Ret()
{
typename mpl::apply_wrap2<default_policy,Ret,lua_to_cpp>::type converter;

m_called = true;
lua_State* L = m_state;

int top = lua_gettop(L);

push_args_from_tuple<1>::apply(L, m_args);
if (m_fun(L, boost::tuples::length<Tuple>::value, 1))
{
assert(lua_gettop(L) == top - m_params + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L);
....





Quote:
The recommended method to get this working at the moment is to provide three wrapper function which the following signatures
bool init0(SoundManager& self);
bool init1(SoundManager& self,const std::string &deviceName);
bool init2(SoundManager& self,const std::string &deviceName, SceneManager* sMan);

I have added
.def("init",(bool(SoundManager::*) (SoundManager &)) &SoundManager::init)
.def("init",(bool(SoundManager::*) (SoundManager &, const std::string &)) &SoundManager::init)
.def("init",(bool(SoundManager::*) (SoundManager &, const std::string &, SceneManager *))&SoundManager::init)




Still I am getting the error.

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

[Edited by - deshan on December 8, 2010 12:03:49 AM]

Share this post


Link to post
Share on other sites
Quote:

I am sorry, It is a lua runtime error. It throws from luabind\detail\call_function.hpp at operator Ret()

Does the exception not fill in the what?

Quote:
The recommended method to get this working at the moment is to provide three wrapper function which the following signatures
bool init0(SoundManager& self);
bool init1(SoundManager& self,const std::string &deviceName);
bool init2(SoundManager& self,const std::string &deviceName, SceneManager* sMan);
I have added
.def("init",(bool(SoundManager::*) (SoundManager &)) &SoundManager::init)
.def("init",(bool(SoundManager::*) (SoundManager &, const std::string &)) &SoundManager::init)
.def("init",(bool(SoundManager::*) (SoundManager &, const std::string &, SceneManager *))&SoundManager::init)
Still I am getting the error.


Yes but they have completely different signatures to what I wrote :)


edit:
This has now been asked on the Luabind mailing list.

[Edited by - dmail on December 8, 2010 9:34:19 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this