Sign in to follow this  
_Sigma

Enumerations?

Recommended Posts

_Sigma    792
enum MyEnumType { ALPHA, BETA, GAMMA }; Is it possible to expose this to AS, so I can call a function using a enumed type in a function call?

Share this post


Link to post
Share on other sites
Malandrin    150
Hi,

The enums are ints, maybe you can use something like this:

// ...
enum MyEnumType { ALPHA, BETA, GAMMA, NUM_TYPES };

static int s_iTypes[ NUM_TYPES ] = { ALPHA, BETA, GAMMA },

engine->RegisterGlobalProperty( "const int ALPHA", &s_iTypes[ ALPHA ] );
engine->RegisterGlobalProperty( "const int BETA", &s_iTypes[ BETA ] );
engine->RegisterGlobalProperty( "const int GAMMA", &s_iTypes[ GAMMA ] );
// ....

Though surely exists an easy form :)

Share this post


Link to post
Share on other sites
_Sigma    792
Never thought of doing it that way! While hacky <BG>, unless Andreas suggests otherwise, I'll use this. Thanks!

//edit: Sorry, silly question: why static?

Share this post


Link to post
Share on other sites
Malandrin    150
When register a global property you need place the variable pointer. That's mean the variable must exists while the script ( asIScriptEngine ) exists. I made the vars static for this reason, but you can use class member variables o whatever you want :)

Share this post


Link to post
Share on other sites
WitchLord    4677
AngelScript still lacks support for enums. One day I'll implement it, but not now.

My suggestion is that you do it like this:


const char *constants =
"const int ALPHA = 0; \n"
"const int BETA = 1; \n"
"const int GAMMA = 2; \n"
"const int NUM_TYPES = 3; \n";

engine->AddScriptSection(0, "constants", constants, strlen(constants));
engine->AddScriptSection(0, "user script", userScript, strlen(userScript));
engine->Build(0);


That is, you declare them in a separate script section. If you wish to get even fancier you can implement support for the #include statement, from the sample in the SDK, and then the script writer can include the constant declarations by himself when he needs them.

Share this post


Link to post
Share on other sites
_Sigma    792
Yes, I have full include support working atm :)

That was going to be default way of doing it...I'll try both of your suggestions,a nd see which ends up working the best.

CHeers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this