Adds remove functions for table to list helper standard library
This commit is contained in:
parent
44bfc90fe3
commit
e74d061177
|
@ -1,5 +1,4 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Upsilon.Evaluator;
|
|
||||||
|
|
||||||
namespace Upsilon.BaseTypes.ScriptTypeInterfaces
|
namespace Upsilon.BaseTypes.ScriptTypeInterfaces
|
||||||
{
|
{
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue