Allow non-local script functions to be called from outside the script

This commit is contained in:
2019-06-05 18:44:23 +02:00
parent 43dede9ae2
commit bda26b0ddf
6 changed files with 50 additions and 4 deletions

View File

@@ -175,3 +175,19 @@ shared_ptr<EvalValue> Evaluator::EvaluateFunctionCallExpression(BoundExpression*
}
EvalValue* Evaluator::EvaluateFunction(ScriptFunctionEvalValue *function, vector<EvalValue *> parameters) {
auto type = std::dynamic_pointer_cast<FunctionScriptType>(function->GetType());
auto parameterTypes = type->GetParameterTypes();
auto parameterKeys = type->GetParameterKeys();
for (int i = 0; i < parameterTypes->size() && i < parameterKeys->size() && i < parameters.size(); i++){
auto parameter = parameters[i];
auto requiredType = parameterTypes->at(i);
if (*parameter->GetType() != requiredType.get()){
throw EvaluationException("Passed wrong type to function.");
}
auto key = parameterKeys->at(i);
this->_evaluationScope->CreateVariable(key->GetScopeId(), key->GetIdentifier(), parameter->Clone());
}
this->EvaluateBlockStatement(function->GetInnerBlock().get());
return nullptr;
}