Fixes for creating variable in local scope
This commit is contained in:
parent
188d89db94
commit
bda561b775
|
@ -67,12 +67,12 @@ BoundVariable *BoundScope::GetVariable(int scope, int identifier) {
|
|||
}
|
||||
|
||||
VariableAssignment BoundScope::CreateExplicitLocal(int identifier, const ScriptType& type) {
|
||||
auto scope = this->_localScope.at(this->_currentScope);
|
||||
auto scope = this->_localScope.at(this->_currentScope - 1);
|
||||
if (scope -> find(identifier) != scope -> end()){
|
||||
return VariableAssignment(VariableAssignmentResult::ExplicitLocalVariableExists, nullptr);
|
||||
}
|
||||
scope -> insert({identifier, new BoundVariable(type)});
|
||||
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, this->_currentScope, true));
|
||||
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, this->_currentScope - 1, true));
|
||||
}
|
||||
|
||||
VariableAssignment BoundScope::AssignVariable(int identifier, const ScriptType& type) {
|
||||
|
|
|
@ -57,3 +57,12 @@ void Script::Parse(string script) {
|
|||
delete parseResult;
|
||||
}
|
||||
|
||||
EvalValue *Script::GetVariable(const string &key) {
|
||||
return _scriptVariables -> at(HashedString(key).GetHash());
|
||||
}
|
||||
|
||||
bool Script::HasVariable(const string &key) {
|
||||
auto f = _scriptVariables->find(HashedString(key).GetHash());
|
||||
return f != _scriptVariables->end();
|
||||
}
|
||||
|
||||
|
|
|
@ -39,9 +39,8 @@ public:
|
|||
return _lastValue;
|
||||
};
|
||||
|
||||
EvalValue* GetVariable(const string& key){
|
||||
return _scriptVariables -> at(HashedString(key).GetHash());
|
||||
}
|
||||
EvalValue* GetVariable(const string& key);
|
||||
bool HasVariable(const string& key);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -14,5 +14,12 @@ TEST_CASE( "Create script variable", "[integration]" ) {
|
|||
delete script;
|
||||
}
|
||||
|
||||
TEST_CASE( "Create local variable", "[integration]" ) {
|
||||
Script* script = Script::Create("local foo = true");
|
||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||
REQUIRE_FALSE(script->HasVariable("foo"));
|
||||
script->Evaluate();
|
||||
delete script;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue