Today I was prompted to make a minor change to the Urho3D sourcecode.
Generally speaking, I prefer to work around such issues, rather than mess with the engine source, however in this case I made an exception.
ScriptFile::Execute supports an optional pointer to receive a return value when executing a script function or method.
ScriptInstance::Execute internally calls ScriptFile::Execute, but does not pass on, or provide for, the optional returnvalue container.
I made the following (harmless?) changes to ScriptInstance.h:
/// Query for a method by declaration and execute. Log an error if not found.
bool Execute(const String& declaration, const VariantVector& parameters = Variant::emptyVariantVector, Variant* rv=nullptr);
/// Execute a method.
bool Execute(asIScriptFunction* method, const VariantVector& parameters = Variant::emptyVariantVector, Variant* rv=nullptr);
And these changes to ScriptInstance.cpp:
bool ScriptInstance::Execute(const String& declaration, const VariantVector& parameters, Variant* rv)
{
if (!scriptObject_)
return false;
asIScriptFunction* method = scriptFile_->GetMethod(scriptObject_, declaration);
if (!method)
{
URHO3D_LOGERROR("Method " + declaration + " not found in class " + className_);
return false;
}
return scriptFile_->Execute(scriptObject_, method, parameters, rv);
}
bool ScriptInstance::Execute(asIScriptFunction* method, const VariantVector& parameters, Variant* rv)
{
if (!method || !scriptObject_)
return false;
return scriptFile_->Execute(scriptObject_, method, parameters, rv);
}
Noting that support for returnvalues was NOT extended to “delayed calls”, the C++ caller (such as my behavior tree nodes) can now receive return values when executing script methods.
This is the first and only change I’ve made in a fresh copy of the engine source I pulled down last week.
If anyone can think of a reason why this change is a bad idea, please let me know!