From f143e526ab9734ca028eba411a37802381aba81e Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 7 Jun 2019 13:51:49 +0200 Subject: [PATCH] Added support for calling script functions from extern C hooks --- src/Evaluator/EvalValues/EvalValue.cpp | 17 +++++++++++++++++ src/Script.cpp | 13 +++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Evaluator/EvalValues/EvalValue.cpp b/src/Evaluator/EvalValues/EvalValue.cpp index 134a437..981fd9c 100644 --- a/src/Evaluator/EvalValues/EvalValue.cpp +++ b/src/Evaluator/EvalValues/EvalValue.cpp @@ -1,4 +1,6 @@ #include "EvalValue.hpp" +#include "NumericEvalValue.hpp" +#include "StringEvalValue.hpp" #include extern "C" { @@ -26,6 +28,21 @@ extern "C" { return v->EvaluateString() -> c_str(); } + EvalValue* CreateIntegerEvalValue(long l){ + return new IntegerEvalValue(l); + } + + EvalValue* CreateFloatEvalValue(double d){ + return new FloatEvalValue(d); + } + + EvalValue* CreateBoolEvalValue(bool b){ + return new BooleanEvalValue(b); + } + + EvalValue* CreateStringEvalValue(const char* s){ + return new StringEvalValue(s); + } } #ifdef TESTS_BUILD diff --git a/src/Script.cpp b/src/Script.cpp index ea7636e..f3ae89a 100644 --- a/src/Script.cpp +++ b/src/Script.cpp @@ -1,6 +1,6 @@ #include - -#include +#include +#include #include #include "Script.hpp" #include "Parser/Lexer.hpp" @@ -97,6 +97,15 @@ extern "C" { EvalValue* GetVariable(Script* script, const char* key){ return script->GetVariable(key); } + + bool HasFunction(Script* script, const char* key){ + return script->HasFunction(key); + } + + EvalValue* CallFunction(Script* script, const char* key, EvalValue* parameters[], int parameterCount){ + std::vector v(parameters, parameters + parameterCount); + return script->CallFunction(key, v); + } }