diff --git a/Upsilon/BaseTypes/ScriptTypeInterfaces/IITerable.cs b/Upsilon/BaseTypes/ScriptTypeInterfaces/IITerable.cs index 09911cb..922d062 100644 --- a/Upsilon/BaseTypes/ScriptTypeInterfaces/IITerable.cs +++ b/Upsilon/BaseTypes/ScriptTypeInterfaces/IITerable.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Upsilon.Evaluator; namespace Upsilon.BaseTypes.ScriptTypeInterfaces { diff --git a/Upsilon/StandardLibraries/ListLibrary.cs b/Upsilon/StandardLibraries/ListLibrary.cs index 927164c..0bb41bf 100644 --- a/Upsilon/StandardLibraries/ListLibrary.cs +++ b/Upsilon/StandardLibraries/ListLibrary.cs @@ -1,5 +1,9 @@ +using System.Collections.Generic; using Upsilon.BaseTypes; +using Upsilon.BaseTypes.ScriptTable; using Upsilon.BaseTypes.ScriptTypeInterfaces; +using Upsilon.BaseTypes.UserData; +using Upsilon.Text; namespace Upsilon.StandardLibraries { @@ -17,5 +21,31 @@ namespace Upsilon.StandardLibraries } return false; } + + [ScriptFunction("remove", "Removes an object from a table.", directScriptManipulation: true)] + public void Remove(ListUserData userList, ScriptType obj) + { + userList.List.Remove(obj); + } + + [ScriptFunction("remove", "Removes an object from a table.", directScriptManipulation: true)] + public void Remove(NumeratedScriptTable scriptTable, ScriptType obj) + { + var enumerator = scriptTable.GetEnumerator(); + var toRemove = new List(); + var i = 1; + while (enumerator.MoveNext()) + { + var current = enumerator.Current; + if (current == obj) + toRemove.Add(i); + i++; + } + enumerator.Dispose(); + foreach (var index in toRemove) + { + scriptTable.Set(null, new TextSpan(), index.ToScriptType(), new ScriptNull()); + } + } } } \ No newline at end of file