🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Exposing a Point class to Angelscript

Started by
4 comments, last by WitchLord 6 years, 1 month ago

Hi all,

I'm trying to expose my Point class to AngelScript, so that it can be used like so:


// This works
Point aPos;
aPos.x=50;
aPos.y=50;

// This doesn't
Point aAnotherPos=Point(1,1);

So first part, no problem... the second part keeps telling me no matching signatures to Point with int, int.

But I do have this:


aResult=gEngine->RegisterObjectMethod("Point","Point &opAssign(const int, const int)", asFUNCTION(AssignPointII),asCALL_GENERIC);

Am I going about this entirely the wrong way?

 

Advertisement

Yes, you're going about this the wrong way. Your opAssign() method needs to be passed a "const Point &in" instead of 2 integers, since that's what you're setting it to in your script.

When I do that, it only tells me that no matching signatures exist for Point(const int, const int) exists.

When I embed this directly in the script:


class Point
{
    float x,y;
};

All the assignments, and equals, and comparisons things work perfectly.  How can I get this behavior so that it uses my point class factory instead?

I mean instead of doing:


Point &opAssign(const int, const int)

You should do this instead:


Point &opAssign(const Point &in)

 

I believe what you're missing is the registration of the constructor so that AngelScript knows that the Point class can be instantiated with Point(1,1). 

 

Learning from examples is probably easier. So just as I said in my e-mail I suggest you take a look at how the Complex class in the script math add-on is registered. Except a few semantic differences the Complex class is probably pretty much identical to your Point class.

http://svn.code.sf.net/p/angelscript/code/trunk/sdk/add_on/scriptmath/scriptmathcomplex.h

http://svn.code.sf.net/p/angelscript/code/trunk/sdk/add_on/scriptmath/scriptmathcomplex.cpp

 

 

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement