Let's consider that I have C++ function which is returning an array of handles of an registered reference type (with reference counting). The object type registered in script engine is "ref" and in C++ it's CRef
The function is registered as "array<ref@>@ CreateArrayOfHandles"
it's looking like this :
CScriptArray *CreateArrayOfHandles()
{
asIScriptContext *ctx = asGetActiveContext();
if( ctx )
{
asIScriptEngine* engine = ctx->GetEngine();
asIObjectType* t = engine->GetObjectTypeById(engine->GetTypeIdByDecl("array<ref@>"));
CScriptArray* arr = new CScriptArray(3, t);
for( unsigned int i = 0; i < arr->GetSize(); i++ )
{
CRef *ptr = new CRef;
arr->SetValue(i, &ptr);
}
return arr;
}
return 0;
}
First, Is it good ?
Second, Will the CRef objects destroyed automatically by script engine ? (CRef is registered as reference type with AddRef and Release functions are registered.)