Make setting a script variable to nil remove that variable
This commit is contained in:
parent
0843c9b624
commit
1e1fa06d12
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue