Refs without AddRef/Release

Started by
1 comment, last by sepul 12 years, 10 months ago
I know I can't create objects without AddRef, Release behaviors, but how can I register Ref objects without implementing AddRef/Release (for example setting _Void function) for them ?
for example singletons or references to existing application objects ?
I just don't want to override all of my classes with AddRef/Release, that's a little bit lame.

I did something like this, and I got assertion failure at registering asBEHAVE_ADDREF behaviour :



r = asEngine->RegisterObjectType( "physics", 0, asOBJ_REF ); HMR_ASSERT(r >= 0);
r = asEngine->RegisterObjectBehaviour( "physics", asBEHAVE_FACTORY, "physics@ f()", asFUNCTION(phys::Physics::Instance()), asCALL_CDECL ); HMR_ASSERT(r >= 0);
r = asEngine->RegisterObjectBehaviour( "physics", asBEHAVE_ADDREF, "void f()", asFUNCTION(_NullFunc), asCALL_CDECL ); HMR_ASSERT(r >= 0);
r = asEngine->RegisterObjectBehaviour( "physics", asBEHAVE_RELEASE, "void f()", asFUNCTION(_NullFunc), asCALL_CDECL ); HMR_ASSERT(r >= 0);
r = asEngine->RegisterObjectMethod( "physics", "void foo()", asMETHOD(phys::Physics, Foo), asCALL_THISCALL );


dark-hammer engine - http://www.hmrengine.com

Advertisement
It fails because asCALL_CDECL is an illegal calling convention in this case, as AngelScript must be able to pass the object pointer to the function. You need a function that takes the object pointer as a parameter, and then you can use for example asCALL_CDECL_OBJLAST convention:


void _NullFunc(Physics *ptr)
{
}

If you have a lot of classes to register without proper reference counting, you can template the _NullFunc:


template <class T> void _NullFunc(T* ptr)
{
}

It fails because asCALL_CDECL is an illegal calling convention in this case, as AngelScript must be able to pass the object pointer to the function. You need a function that takes the object pointer as a parameter, and then you can use for example asCALL_CDECL_OBJLAST convention:


void _NullFunc(Physics *ptr)
{
}

If you have a lot of classes to register without proper reference counting, you can template the _NullFunc:


template <class T> void _NullFunc(T* ptr)
{
}



thanks for the hint

dark-hammer engine - http://www.hmrengine.com

This topic is closed to new replies.

Advertisement