Enumerations?
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?
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 :)
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 :)
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?
//edit: Sorry, silly question: why static?
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 :)
AngelScript still lacks support for enums. One day I'll implement it, but not now.
My suggestion is that you do it like this:
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.
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.
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
Popular Topics
Advertisement