diff --git a/CommandBasicIO.cs b/CommandBasicIO.cs index 0a782c7..23c8ff3 100644 --- a/CommandBasicIO.cs +++ b/CommandBasicIO.cs @@ -191,6 +191,27 @@ public override void Evaluate() } } + [CommandAttribute("UNSET %")] + public class CommandUnset : Command + { + public CommandUnset(Match regexMatch, ExecutionContext context) : base(regexMatch, context) { } + + public override void Evaluate() + { + String varname = RegexMatch.Groups[1].Value; + + if (varname.ToUpper() == "ALL") + { + ParentContext.UnsetAll(); + } + else + { + ParentContext.Unset(varname); + } + + State = ExecutionState.DONE; + } + } [CommandAttribute("TOGGLE %")] public class CommandToggle : Command { diff --git a/ExecutionContext.cs b/ExecutionContext.cs index caaa846..271f0aa 100644 --- a/ExecutionContext.cs +++ b/ExecutionContext.cs @@ -290,6 +290,32 @@ public virtual void UnlockAll() if (ParentContext != null) ParentContext.UnlockAll(); } + public virtual void Unset(String name) + { + if (Variables.ContainsKey(name.ToLower())) + { + Variables.Remove(name.ToLower()); + } + else if (ParentContext != null) + { + ParentContext.Unset(name.ToLower()); + } + } + + public virtual void UnsetAll() + { + for( int i = 0; i < Variables.Count; i++) + { + var currvar = Variables.ElementAt(i); + + if(!(currvar.Value is BoundVariable)) + { + Variables.Remove(currvar.Key); + } + } + if (ParentContext != null) ParentContext.UnsetAll(); + } + public bool parseNext(ref string buffer, out string cmd, ref int lineCount, out int lineStart) { lineStart = -1;