Advertisement

Type-Casting single reference types

Started by December 10, 2012 05:05 PM
1 comment, last by BClarenbach 11 years, 9 months ago
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.
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

Advertisement
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.

This topic is closed to new replies.

Advertisement