Make setting a script variable to nil remove that variable

This commit is contained in:
Deukhoofd 2018-12-09 19:02:35 +01:00
parent 0843c9b624
commit 1e1fa06d12
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 16 additions and 1 deletions

View File

@ -27,13 +27,18 @@ namespace Upsilon.BaseTypes.ScriptTable
{ {
return o; return o;
} }
diagnostics.LogError("Cannot find member 's' on Table", span); diagnostics.LogError($"Cannot find member '{s}' on Table", span);
return new ScriptNull(); return new ScriptNull();
} }
public void Set(Diagnostics diagnostics, TextSpan span, ScriptType index, ScriptType value) public void Set(Diagnostics diagnostics, TextSpan span, ScriptType index, ScriptType value)
{ {
var s = index.ToString(); var s = index.ToString();
if (value.Type == Type.Nil)
{
EvaluationScope.Delete(s);
return;
}
EvaluationScope.CreateLocal(new VariableSymbol(s, value.Type, false), value); EvaluationScope.CreateLocal(new VariableSymbol(s, value.Type, false), value);
} }

View File

@ -59,6 +59,16 @@ namespace Upsilon.Evaluator
Variables[symbol.Name] = value; Variables[symbol.Name] = value;
} }
public void Delete(VariableSymbol symbol)
{
Variables.Remove(symbol.Name);
}
public void Delete(string name)
{
Variables.Remove(name);
}
public bool TryGet(VariableSymbol symbol, out ScriptType obj) public bool TryGet(VariableSymbol symbol, out ScriptType obj)
{ {