Exemple #1
0
bool ScriptFile::Execute(asIScriptObject* object, asIScriptFunction* method, const VariantVector& parameters, bool unprepare)
{
    PROFILE(ExecuteMethod);
    
    if (!compiled_ || !object || !method)
        return false;
    
    // It is possible that executing the method causes us to unload. Therefore do not rely on member variables
    // However, we are not prepared for the whole script system getting destroyed during execution (should never happen)
    Script* scriptSystem = script_;
    
    asIScriptContext* context = scriptSystem->GetScriptFileContext();
    if (context->Prepare(method) < 0)
        return false;
    
    context->SetObject(object);
    SetParameters(context, method, parameters);
    
    scriptSystem->IncScriptNestingLevel();
    bool success = context->Execute() >= 0;
    if (unprepare)
        context->Unprepare();
    scriptSystem->DecScriptNestingLevel();
    
    return success;
}