Advertisement Jump to content
Sign in to follow this  
Violet CLM

Indexed property accessors and namespaces

This topic is 2236 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 have an array I would like to expose to Angelscript (using v2.25.2):
[source lang="cpp"]bool getTrigger(Word8 id) {
return triggers[id&31] == 1;
bool setTrigger(Word8 id, bool setTo) {
return (triggers[id&31] = (setTo)) ? 1 : 0;
}[/source] [size=1](no comments on the switching from booleans to int8 values, please, it's for unrelated reasons)
I register the get function as follows:
[source lang="cpp"]ASengine->RegisterGlobalFunction("bool get_triggers(uint8)", asFUNCTION(getTrigger), asCALL_CDECL);[/source]
Trying to access it through Angelscript, I get this paradigm:
triggers[0] //this works fine, thankfully
foo::triggers[0] //this also works fine, but shouldn't

On the other hand, if I register the get function in a namespace
[source lang="cpp"]ASengine->SetDefaultNamespace("Game");
ASengine->RegisterGlobalFunction("bool get_triggers(uint8)", asFUNCTION(getTrigger), asCALL_CDECL);[/source]
I get this:
triggers[0] //ERR : 'triggers' is not declared
Game::triggers[0] //ERR : 'Game::triggers' is not declared
foo::triggers[0] //ERR : 'foo::triggers' is not declared
Game::get_triggers(0) //works
get_triggers(0) //doesn't work
foo::get_triggers(0) //doesn't work

I can also register it any of the following ways:
[source lang="cpp"]ASengine->RegisterGlobalFunction("bool Game::get_triggers(uint8)", asFUNCTION(getTrigger), asCALL_CDECL);
ASengine->RegisterGlobalFunction("Game::bool get_triggers(uint8)", asFUNCTION(getTrigger), asCALL_CDECL);
ASengine->RegisterGlobalFunction("Game::bool Game::get_triggers(uint8)", asFUNCTION(getTrigger), asCALL_CDECL);[/source]
the latter two of which probably shouldn't even compile, and still get the same results.

(Everything I mention applies to the set function too, so I left it out for the sake of brevity.) As I understand it, proper behavior would be for get_triggers registered outside of any namespaces to be accessible only as "triggers", never as "foo::triggers", and get_triggers registered inside a namespace to be accessible only as "foo::triggers" instead of, well, never. Is this the right intended behavior? It's not what I'm getting. Edited by Andreas Jonsson

Share this post

Link to post
Share on other sites
You seem to have discovered a bug related to namespaces and virtual property accessors in AngelScript.

I'll have a look at this.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!