Indexed property accessors and namespaces

Started by
1 comment, last by WitchLord 11 years, 4 months ago
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.
Advertisement
You seem to have discovered a bug related to namespaces and virtual property accessors in AngelScript.

I'll have a look at this.

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

I've fixed these problems in revision 1492.

Thanks,
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

This topic is closed to new replies.

Advertisement