Rework evaluation to use shared pointers, fix bugs

This commit is contained in:
2019-06-01 21:38:39 +02:00
parent 4408cf00cd
commit 6206fef4c5
17 changed files with 122 additions and 133 deletions

View File

@@ -16,7 +16,7 @@ Script::Script() {
_evaluator = new Evaluator(this);
_lastValue = nullptr;
BoundScript = nullptr;
_scriptVariables = new unordered_map<int, EvalValue*>(0);
_scriptVariables = new unordered_map<int, shared_ptr<EvalValue>>(0);
}
void Script::Evaluate() {
@@ -26,11 +26,7 @@ void Script::Evaluate() {
Script::~Script() {
delete this -> Diagnostics;
delete this -> BoundScript;
delete this -> _lastValue;
delete this -> _evaluator;
for (auto v : *this->_scriptVariables){
delete v.second;
}
this->_scriptVariables->clear();
delete this->_scriptVariables;
}
@@ -58,7 +54,7 @@ void Script::Parse(string script) {
}
EvalValue *Script::GetVariable(const string &key) {
return _scriptVariables -> at(HashedString(key).GetHash());
return _scriptVariables -> at(HashedString(key).GetHash()).get();
}
bool Script::HasVariable(const string &key) {