Skip to main content
GameDev.net gamedev.net
🔒 Locked

lua runtime error when inheriting from c++ classes

Started by Nanoha Mar 12, 2011 at 4:17 PM 0 replies 1.2k views
Original Post
Nanoha
Nanoha
I have a class that I expose to lua using luabind. I then inherit from this class and overide some of its functionality. All works well and if I don't define a particular function in lua then the default c++ one is called. I'm trying to add another method to this class with more or less the exact same format but this particular method will not work. I get the following error when the method is not defined in lua (if I define the class in lua all works well but I want the defaults):

lua runtime error: No matching overload found, candidates:
void OnRender(custom [class Overkill::GameState]*, unsigned int)

This is how I'm defining/exposing my class. I've included a similar method that does work.

Declaration:

class IGameState
{
public:
virtual void OnRender(unsigned int elapsedMiliseconds) = 0;
virtual void OnEnter(GameStateMachine *stateMachine) = 0;
};

class GameState: public IGameState
{
public:
virtual void OnRender(unsigned int elapsedMiliseconds);
virtual void OnEnter(GameStateMachine *stateMachine);
};

class GameStateWrapper: public GameState, public luabind::wrap_base
{
public:
virtual void OnEnter(GameStateMachine *stateMachine);
static void DefaultOnEnter(GameState *ptr, GameStateMachine *stateMachine);

virtual void OnRender(unsigned int elapsedMiliseconds);
static void DefaultOnRender(GameState *ptr, unsigned int elapsedMiliseconds);
};


Implementation:

void GameState::OnEnter(GameStateMachine *stateMachine)
{
assert(!m_Parent && "m_Parent != NULL");
m_Parent = stateMachine;
}

void GameState::OnRender(unsigned int elapsedMiliseconds)
{
m_Root->renderOneFrame();
}

void GameStateWrapper::OnEnter(GameStateMachine *stateMachine)
{
call<void>("OnEnter", stateMachine);
}

void GameStateWrapper::DefaultOnEnter(GameState *ptr, GameStateMachine *stateMachine)
{
ptr->GameState::OnEnter(stateMachine);
}

void GameStateWrapper::OnRender(unsigned int elapsedMiliseconds)
{
call<void>("OnRender", elapsedMiliseconds);
}

void GameStateWrapper::DefaultOnRender(GameState *ptr, unsigned int elapsedMiliseconds)
{
ptr->GameState::OnRender(elapsedMiliseconds);
}


This is how I'm exposing them:

module(state)
[
namespace_("Overkill")
[
class_<GameStateWrapper, GameStatePtr>("GameState")
.def("OnEnter", &GameState::OnEnter, &GameStateWrapper::DefaultOnEnter)
.def("OnRender", &IGameState::OnRender, &GameStateWrapper::DefaultOnRender)
]
];


I've read around this problem alot, mostly solved but the solutions haven't fixed this. I've tried all sorts, tried changing the function names, changin the parameters, removing the parameters, using free functions, defining the base classes. This is pretty much exactly the same as shown here just with different names. I've also cleaned and rebuilt several times.

If I add this to my script:

function TitleScreenState:OnRender(ms)
self.root:renderOneFrame();
end


Then all works well, I don't define some of the other methods and they also work ok, its just this OnRender one (althought with completely different names and parameters it still doens't work which is odd).

Thanks
Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.
dmail
dmail
Im my opinion as this is a Luabind problem it would be better to post to the libraries mailing list hosted on sourceforge, where the maintainer and other users can comment and document the required fix for anybody else having the same problem


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.