• Create Account

### #Actualcellulose

Posted 21 June 2012 - 11:38 AM

I'm curious about future prospects on a function call operator in Angelscript. Messy though they can be, operator() overloads are super-useful and something I use frequently in C++ to avoid wordy APIs. It also allows for functors and the like.

As an example, I have a module called "Random" in my game engine, exposed to Angelscript as a global, which can generally be treated like an overloaded function to generate random numbers with various parameters. Additional Random objects can also be created for deterministic simulations and the like, so I'd be losing some functionality if I just exposed this stuff as global functions.

class Random
{
public:
Uint32 operator()(Uint32 max);
Uint32 operator()(Uint32 min, Uint32 max);

Sint32 operator()(Sint32 max);
Sint32 operator()(Sint32 min, Sint32 max);

float operator()(float max);
float operator()(float min, float max);

double operator()(double max);
double operator()(double min, double max);

// Normal distribution
float normal(float mean, float deviation);

// Exponential normal distribution
float normalExp(float mean, float multDeviation);

// ...
};


Is this something that is likely to be added to Angelscript in the future, or would it throw a wrench in the design?

### #1cellulose

Posted 21 June 2012 - 11:35 AM

I'm curious about future prospects on a function call operator in Angelscript. Messy though they can be, operator() overloads are super-useful and something I use frequently in C++ to avoid wordy APIs. It also allows for functors and the like.

As an example, I have a module called "Random" in my game engine, exposed to Angelscript as a global, which can generally be treated like an overloaded function to generate random numbers with various parameters.

class Random
{
public:
Uint32 operator()(Uint32 max);
Uint32 operator()(Uint32 min, Uint32 max);

Sint32 operator()(Sint32 max);
Sint32 operator()(Sint32 min, Sint32 max);

float operator()(float max);
float operator()(float min, float max);

double operator()(double max);
double operator()(double min, double max);

// Normal distribution
float normal(float mean, float deviation);

// Exponential normal distribution
float normalExp(float mean, float multDeviation);

// ...
};


Is this something that is likely to be added to Angelscript in the future, or would it throw a wrench in the design?

PARTNERS