Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Indexed property accessors and namespaces


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Violet CLM   Members   -  Reputation: 185

Like
0Likes
Like

Posted 28 November 2012 - 09:27 PM

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] (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, 06 December 2012 - 05:39 PM.


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3200

Like
0Likes
Like

Posted 29 November 2012 - 09:07 AM

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

#3 Andreas Jonsson   Moderators   -  Reputation: 3200

Like
0Likes
Like

Posted 06 December 2012 - 05:39 PM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS