Hi!
I try to implement passing delegates as arguments from script and call it from c++.
i use follow code to store script function -
void ScriptModuleCore::Network::SetDelegate(DelegateAS& delegateAS, asIScriptFunction* cb)
{
asIScriptEngine* engine = ((ScriptMachine*)(core->Script()->Machine()))->Machine();
if (delegateAS.callback)
{
delegateAS.callback->Release();
}
if (delegateAS.callbackObject)
{
engine->ReleaseScriptObject(delegateAS.callbackObject, delegateAS.callbackObjectType);
}
delegateAS.callback = 0;
delegateAS.callbackObject = 0;
delegateAS.callbackObjectType = 0;
if( cb && cb->GetFuncType() == asFUNC_DELEGATE )
{
delegateAS.callbackObject = cb->GetDelegateObject();
delegateAS.callbackObjectType = cb->GetDelegateObjectType();
delegateAS.callback = cb->GetDelegateFunction();
engine->AddRefScriptObject(delegateAS.callbackObject, delegateAS.callbackObjectType);
delegateAS.callback->AddRef();
cb->Release();
}
else
{
delegateAS.callback = cb;
}
}
follow code executes script function
asIScriptContext* ctx = GrabContext();
ctx->Prepare(script_func);
ctx->SetObject(hack_callbackObject);
ctx->Execute();
All fine when we deal with just function. But if we pass delegate than we got assertion in AngelScript in follow function -
// internal
int asCScriptFunction::GetRefCount()
{
asASSERT( funcType == asFUNC_DELEGATE );
return externalRefCount.get();
}
Maybe i just doing something wrong when dealing with delegate from c++ or this is bug in AngelScript?