Adds remove functions for table to list helper standard library

This commit is contained in:
Deukhoofd 2019-01-21 13:52:02 +01:00
parent 44bfc90fe3
commit e74d061177
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 30 additions and 1 deletions

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using Upsilon.Evaluator;
namespace Upsilon.BaseTypes.ScriptTypeInterfaces namespace Upsilon.BaseTypes.ScriptTypeInterfaces
{ {

View File

@ -1,5 +1,9 @@
using System.Collections.Generic;
using Upsilon.BaseTypes; using Upsilon.BaseTypes;
using Upsilon.BaseTypes.ScriptTable;
using Upsilon.BaseTypes.ScriptTypeInterfaces; using Upsilon.BaseTypes.ScriptTypeInterfaces;
using Upsilon.BaseTypes.UserData;
using Upsilon.Text;
namespace Upsilon.StandardLibraries namespace Upsilon.StandardLibraries
{ {
@ -17,5 +21,31 @@ namespace Upsilon.StandardLibraries
} }
return false; 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<int>();
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());
}
}
} }
} }