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

@@ -1,3 +1,5 @@
#include <utility>
#include <utility>
#include <unordered_map>
#include "Script.hpp"
@@ -65,6 +67,16 @@ EvalValue *Script::GetLastValue() {
return _evaluator->GetLastValue();
}
bool Script::HasFunction(const string &key) {
auto f = _scriptVariables->find(HashedString(key).GetHash());
return f != _scriptVariables->end() && f.operator->()->second->GetType()->GetClass() == TypeClass ::Function;
}
EvalValue *Script::CallFunction(const string &key, vector<EvalValue *> variables) {
auto var = (ScriptFunctionEvalValue*)GetVariable(key);
return this->_evaluator->EvaluateFunction(var, std::move(variables));
}
extern "C" {
Script* CreateScript(char * s){
return Script::Create(s);