Work to add C style entry points to library that allow most functionality

This commit is contained in:
2019-06-05 17:46:46 +02:00
parent 6206fef4c5
commit 43dede9ae2
14 changed files with 169 additions and 79 deletions

View File

@@ -14,18 +14,17 @@ Script* Script::Create(string script) {
Script::Script() {
Diagnostics = new class Diagnostics();
_evaluator = new Evaluator(this);
_lastValue = nullptr;
BoundScript = nullptr;
_boundScript = nullptr;
_scriptVariables = new unordered_map<int, shared_ptr<EvalValue>>(0);
}
void Script::Evaluate() {
_evaluator->Evaluate(BoundScript);
_evaluator->Evaluate(_boundScript);
}
Script::~Script() {
delete this -> Diagnostics;
delete this -> BoundScript;
delete this -> _boundScript;
delete this -> _evaluator;
this->_scriptVariables->clear();
delete this->_scriptVariables;
@@ -43,7 +42,7 @@ void Script::Parse(string script) {
if (!Diagnostics->HasErrors()){
unordered_map<int, BoundVariable*> scriptScope;
auto bindScope = new BoundScope(&scriptScope);
this->BoundScript = Binder::Bind(this, parseResult, bindScope);
this->_boundScript = Binder::Bind(this, parseResult, bindScope);
for (const auto& v : scriptScope){
this->_scriptVariables -> insert({v.first, nullptr});
delete v.second;
@@ -62,3 +61,30 @@ bool Script::HasVariable(const string &key) {
return f != _scriptVariables->end();
}
EvalValue *Script::GetLastValue() {
return _evaluator->GetLastValue();
}
extern "C" {
Script* CreateScript(char * s){
return Script::Create(s);
}
void EvaluateScript(Script* script){
script->Evaluate();
}
EvalValue* GetLastValue(Script* script){
return script->GetLastValue();
}
bool HasVariable(Script* script, const char* key){
return script->HasVariable(key);
}
EvalValue* GetVariable(Script* script, const char* key){
return script->GetVariable(key);
}
}