🎉 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!

pointers/arrays in AS 2.0

Started by
2 comments, last by WitchLord 19 years, 5 months ago
Hi, I have a c function that looks something like this:

const float *getPosition();


The returned float-pointer is an array with x in [0], y in [1] and z in [2]. What would be the proper way to register this function with angelscript?
Advertisement
There is unfortunately no easy way to register this. My suggestion is that you write a wrapper function that returns a registered Vector3 object by value.

Vector3 getPositionWrapper()
{
const float *pos = getPosition();
return Vector3(pos[0], pos[1], pos[2]);
}

You can't register the function directly because the script language cannot guarantee that the object is read-only. (I removed const for objects because of this.) If the language could guarantee const for objects it would have been possible to register the function to return a reference to a Vector3 object.

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

Thanks.

That was what I was thinking. Just wanted to make sure it was the correct way to handle the situation so that I don't have to go back and change everything at a later time =)
I want to allow const for objects again in the future. I will make an effort to add this already for 2.1.0 (next version) but I don't guarantee anything.

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