Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

Type-Casting single reference types


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 BClarenbach   Members   -  Reputation: 130

Like
0Likes
Like

Posted 10 December 2012 - 11:05 AM

Hi,

I have a couple of objects that I currently introduce as single reference types into the scripting environment. This is because they are in-place allocated in a special memory manager. They obviously do not have any ref counting behaviours, either.

Now the management class only handles base pointers to the class hierarchy. I would like to create casting behaviours in AS now so that I can safely cast the types up and down the hierarchy.

I am not able to register the type casting like it is documented in the Class Hierarchies chapter of the manual. Returning by value is obviously wrong, returning by @ is equally wrong since there is no ref counting. Returning by & returns an error when I try to register the type cast.

Any ideas or hints on what I could also do?

Thanks!
Working with STL makes a lot more sense if you think about the "std::" as referring to Sexually Transmitted Diseases.

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3366

Like
1Likes
Like

Posted 10 December 2012 - 03:50 PM

I think the safest solution would be to register explicit methods that return a & to the other type, rather than attempting the use of the cast operator. If these other types are also registered as single reference types this should work, without allowing the script to keep references to the cast type.

If you don't care if the script keep handles to these in-place allocated objects you can register them as asOBJ_REF | asOBJ_NOCOUNT. AngelScript will then treat them as ordinary reference types, except that it will not attempt to call AddRef or Release on them.
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 BClarenbach   Members   -  Reputation: 130

Like
0Likes
Like

Posted 11 December 2012 - 03:59 AM

Thanks, NOCOUNT did what I wanted. :) I know the lifetime of both objects and scripts, so there is no danger of dangling references
Working with STL makes a lot more sense if you think about the "std::" as referring to Sexually Transmitted Diseases.




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