Sign in to follow this  

Type-Casting single reference types

Recommended Posts

BClarenbach    130

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?


Share this post

Link to post
Share on other sites
WitchLord    4677
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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this