Jump to content
  • Advertisement
Sign in to follow this  
Starfox

Registering strongly-typed class nested enums

This topic is 1663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites

:( 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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!