Advertisement

Registering strongly-typed class nested enums

Started by May 23, 2014 10:22 PM
2 comments, last by WitchLord 10 years, 6 months ago

I'm using AS 2.24.0. I have a class like this:

[source]

class foo

{

public:

enum class state : int { a = 0, b, c };

};

[/source]

I want to register that in AngelScript. I have registration code like this:

[source]

Engine->RegisterObjectType("foo", sizeof(foo), asOBJ_REF | asOBJ_NOCOUNT);
//
Engine->RegisterEnum("foo::state");
Engine->RegisterEnumValue("foo::state", "stopped", static_cast<int>(foo::state::a));
Engine->RegisterEnumValue("foo::state", "playing", static_cast<int>(foo::state::b));
Engine->RegisterEnumValue("foo::state", "paused", static_cast<int>(foo::state::c));

[/source]

However, I seem to be getting errors due to the following piece of AS code in asCScriptEngine::ResgisterEnum:

[source]

// Make sure the name is not a reserved keyword
size_t tokenLen;
int token = tok.GetToken(name, strlen(name), &tokenLen);
if( token != ttIdentifier || strlen(name) != tokenLen )
return ConfigError(asINVALID_NAME, "RegisterEnum", name, 0);

[/source]

What am I doing wrong here?

Holy crap I started a blog - http://unobvious.typepad.com/

The AngelScript language does not yet support declaring enums as members of classes, so it doesn't understand "foo::state".

You'll need to register the class enum as a global enum in the script. You can put it in a different namespace or use a prefix to avoid name conflict if there is one.

Regards,

Andreas

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

Advertisement

:( I'm a bit heartbroken. I would have loved to have parity between C++ and AngelScript syntax. This wouldn't affect us much since our AS script path is in maintenance mode while we transition to Lua (for a bunch of unrelated reasons) but I'd love to see support for class enums in AS eventually.

Holy crap I started a blog - http://unobvious.typepad.com/

It will eventually be supported. :) Though I cannot say when I'll get to implement it.

May I ask why you're transitioning away from AS? It's always good to know what is not seen as good enough, so I can improve it.

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