Sign in to follow this  

Luabind unable to find a method declared in the superclass

This topic is 3454 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm currently enjoying myself with a small command line RPG in C++ using Lua scripts. I'm using Lua through Luabind library. Although this library is really very very user-friendly, I still managed to find a difficulty using it : I have the Player class directly deriving from Combattant. Combattant has a Create(const string&, int) method for creating named attributes such as defense, attack_power, etc. Since Player directly inherits from Combattant, I think I need to register the Create method only once for Combattant. The problem is that when my Lua script calls the Create method with a string and a number as parameters, I catch an exception with the following message : no overload of 'Player:Create' matched the arguments (string, number) candidates are: Player:Create(const string&, number) I tried to reproduce the problem with the constructor of another class and I noticed that the occurrence of the error depended upon the way I declared the constructor and the way I registered it for Lua calls. Weirdly, when I declare the method as Create(std::string,int), the exception message still says that only the method Player:Create(string,number) was found when looking for Player:Create(string,number). Since Create is a method and not a constructor, luabind does not let me declare the type of the expected parameters in the luabind::class_::def method. Does someone know why Luabind is not able to find a method whereas the parameter list is right? I thought that might be related to the policies ; I currently use none of them. Thanks in advance to all, cheers.

Share this post


Link to post
Share on other sites
Hi again,
Since I received no answer to my thread, I think I should re-ask my question in a clearer way.
Does someone know whether there is something special to do when one wants to use a n inherited C++ method from a Lua script?
For example, must I redeclare the method in each subclass (I guess the answer is no), or must I declare special policies or something like that?

Please help me, out of pity!!!!
Thanks in advance, cheers!

Share this post


Link to post
Share on other sites
I'm assuming your Create method is static which may be a gotcha.


class_<Combatant>("Combatant")
.scope
[
.def("Create", &Create)
] ;
// Add methods for Combatant

class_<Player, Combatant>("Player")
// Add methods for Player



If that doesn't work then it might be best to start showing your headers and the binding code in question.

Share this post


Link to post
Share on other sites
Hi!
Thanks for your try but my method is not static, buddy! (unless I was really very very exhausted when I coded the stuff).

I don't have the whole code in my head right now but it should look like the code lower.
I suppose I have to declare the methods only once for Lua if they are inherited.
Is there a way to upload code files to GameDev if this is needed?

When I call the Create method on a Player object created from a Lua script, I get an error message saying that the method has not been found.
Note that I tried to change the method's prototype (I used a string reference, a const string reference, a mere string, etc.) but nothing could help.
I hope you'll have an idea.
Anyway, thanks a lot for your guidance!!


// header files
class Combattant : public Character{
...
public:
static class_<Combattant,Character> Register();
void Create(const std:string &attr, int value);
...
};

class Player : public Combattant{
...
public:
static class_<Player,Combattant> Register();
...
};

// source files
class_<Combattant,Character> Combattant::Register(){
return class_<Combattant,Character>("Combattant")
.def("Create", &Combattant::Create);
}

class_<Player,Combattant> Player::Register(){
return class_<Player,Combattant>("Player");
}


Share this post


Link to post
Share on other sites
If you create a Combatant in a Lua script what happens when you call the create method on it?

Also when are these static Register methods getting called in your code?

Share this post


Link to post
Share on other sites
Hi again!
The Register static methods are called since the beginning of the execution (ie the main function surely calls a kind of Register all function that appends all the classes to the luabind::module).

Regarding your first question, I can actually not remember what happens if I directly try with a Combattant instance but I think this is a really good question. I'm not at home right now but I will try this ASAP.

Do you know if (and how) I can upload source files to let you see them?
Thanks again for your help, dude!!
Cheers!!

Share this post


Link to post
Share on other sites

This topic is 3454 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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