ChaiScript: Exposing data member variables of a class

1.4k views Asked by At

I'm trying to expose Ogre::Vector2 class to ChaiScript. I want to expose the x and y of the class and as-per this post on their forum, it seems like you just need to add it like any other function. But that doesn't work for me and it gives me the following error message:

"Error with function dispatch for function 'x'" With parameters: (const class Ogre::Vector2).()

NOTE: I've tried accessing them as v.x and v.x() inside of the script.

My definition of the module looks like this:

using namespace chaiscript;
ModulePtr module(new Module());
module->add(user_type<Ogre::Vector2>(), "Ogre::Vector2");
module->add(constructor<Ogre::Vector2()>(), "Ogre::Vector2");
module->add(constructor<Ogre::Vector2(float, float)>(), "Ogre::Vector2");
module->add(constructor<Ogre::Vector2(float)>(), "Ogre::Vector2");
module->add(constructor<Ogre::Vector2(const Ogre::Vector2&)>(), "Ogre::Vector2");
module->add(fun(&Ogre::Vector2::x), "x");
module->add(fun(&Ogre::Vector2::y), "y");
module->add(fun<Ogre::Vector2& (Ogre::Vector2::*)(const Ogre::Vector2&)>(&Ogre::Vector2::operator =), "=");
module->add(fun<Ogre::Vector2 (Ogre::Vector2::*)(const Ogre::Vector2&) const>(&Ogre::Vector2::operator+), "+");
module->add(fun<Ogre::Vector2 (Ogre::Vector2::*)(const Ogre::Vector2&) const>(&Ogre::Vector2::operator-), "-");
module->add(fun<Ogre::Vector2 (Ogre::Vector2::*)(const Ogre::Vector2&) const>(&Ogre::Vector2::operator*), "*");
module->add(fun<Ogre::Vector2 (Ogre::Vector2::*)(const float) const>(&Ogre::Vector2::operator*), "*");
module->add(fun<Ogre::Vector2 (Ogre::Vector2::*)(const Ogre::Vector2&) const>(&Ogre::Vector2::operator/), "/");
module->add(fun<Ogre::Vector2 (Ogre::Vector2::*)(const float) const>(&Ogre::Vector2::operator/), "/");

I had initially tried defining this class via their class helper macro and went on to manually define this module by-hand having encountered this error. Since their forum has disabled new-topic creations and new posts (DARN you, spammers!), I'm posting this question here. Any help to resolve this issue would be much appreciated.

NOTE2: I'm using ChaiScript-4.2.0

0

There are 0 answers