Sign in to follow this  

Trouble with &inout

Recommended Posts

I'm trying to bind a global function that has a pointer to an &inout object handle as parameter. That's my object:
r = pASEngine->RegisterObjectType("Entity", 0, asOBJ_REF); assert(r >= 0);
r = pASEngine->RegisterObjectBehaviour("Entity", asBEHAVE_ADDREF, "void f()", asFUNCTION(DummyAddRef),  asCALL_CDECL_OBJLAST); assert(r >= 0);
r = pASEngine->RegisterObjectBehaviour("Entity", asBEHAVE_RELEASE, "void f()", asFUNCTION(DummyRelease),  asCALL_CDECL_OBJLAST); assert(r >= 0);

That's the global function:
r = m_pASEngine->RegisterGlobalFunction("bool DeleteEntity(Entity@ &inout)", asFUNCTION(DeleteEntity), asCALL_CDECL); assert(r >= 0);

I receive the following error message:
Only object types that support object handles can use &inout. Use &in or &out instead.
This one works fine:
r = m_pASEngine->RegisterGlobalFunction("bool Collide(const Entity &in, Entity@ &out)", asFUNCTION(CollideStatic), asCALL_CDECL); assert(r >= 0);

My reference object has been working with and @&out very fine so far. Why is that? I suppose AngelScript doesn't support @&in, I am right? I googled the documentation and I haven't found anything about that.

Share this post

Link to post
Share on other sites
Entity &inout is allowed but not Entity@ &inout

This is because the Entity object is reference counted but not the handle to Entity object.

How did you plan on implementing the DeleteEntity function? I hope you weren't planning on calling delete on the received object directly. That would be highly risky as there's no telling what other references to the object that are still hanging around.

Share this post

Link to post
Share on other sites
The reason why I wanted to use an @&inout is that after deleting the object that it pointed to I would set its pointer to null, making it safer.
But that's ok, I'll implement a shared pointer using a proxy object. I should have done that from the beginning... now that the Entity object has lot's of methods it's going to be much harder.

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