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 { internal class ListLibrary { [ScriptFunction("contains", "Returns a boolean that defines whether a table contains a value", directScriptManipulation: true)] public ScriptBoolean Contains(IIterable table, ScriptType obj) { return table.Contains(obj); } [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()); } } } }