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

Creating constructors for basic data types

Started by
0 comments, last by WitchLord 16 years, 2 months ago
Hey, In my game im using AngelScript and i want to be able to convert a "string" into a number by doing this:

string test = "2224";
int someNumber = int(test);
Is there a way to do this? In your string class, you can convert a NUMBER to a STRING just by doing this:
string test = 2224;
But in my string class (which is a modification of yours) to convert a number to a string you do this:
string test;
test = string(2224);
//Doing it this way, i dont have to register the string operators for
//every data type, i just create a constructor for every data type
I would like to do the same when converting a string to a number.
Advertisement
The asBEHAVE_VALUE_CAST behaviour was implemented for this very purpose.

This behaviour is registered as an object behaviour, like this:

r = engine->RegisterObjectBehaviour("obj", asBEHAVE_VALUE_CAST, "int f()", asFUNCTION(Obj_castInt), asCALL_GENERIC); 


The above behaviour will let AngelScript implicitly cast objects of type 'obj' to int, by calling this method.

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