Added support for calling script functions from extern C hooks
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-06-07 13:51:49 +02:00
parent a747c60f32
commit f143e526ab
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 28 additions and 2 deletions

View File

@ -1,4 +1,6 @@
#include "EvalValue.hpp"
#include "NumericEvalValue.hpp"
#include "StringEvalValue.hpp"
#include <cstring>
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

View File

@ -1,6 +1,6 @@
#include <utility>
#include <utility>
#include <vector>
#include <iterator>
#include <unordered_map>
#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<EvalValue*> v(parameters, parameters + parameterCount);
return script->CallFunction(key, v);
}
}