Better handling of list.contains()
This commit is contained in:
parent
6bc3469860
commit
768c02c482
|
@ -30,7 +30,10 @@ namespace Upsilon.BaseTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract IEnumerator<ScriptType> GetScriptEnumerator();
|
public abstract IEnumerator<ScriptType> GetScriptEnumerator();
|
||||||
|
public bool Contains(ScriptType obj)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class UpTillNullPairsScriptIterator : ScriptIterator
|
internal class UpTillNullPairsScriptIterator : ScriptIterator
|
||||||
|
|
|
@ -28,5 +28,10 @@ namespace Upsilon.BaseTypes.ScriptTable
|
||||||
yield return variable.Key.ToScriptType();
|
yield return variable.Key.ToScriptType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Contains(ScriptType obj)
|
||||||
|
{
|
||||||
|
return EvaluationScope.TryGet(obj.ToString(), out _);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,6 +19,11 @@ namespace Upsilon.BaseTypes.ScriptTable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Contains(ScriptType obj)
|
||||||
|
{
|
||||||
|
return EvaluationScope.Variables.Values.Contains(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public override System.Type GetCSharpType()
|
public override System.Type GetCSharpType()
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,6 +51,7 @@ namespace Upsilon.BaseTypes.ScriptTable
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract IEnumerator<ScriptType> GetScriptEnumerator();
|
public abstract IEnumerator<ScriptType> GetScriptEnumerator();
|
||||||
|
public abstract bool Contains(ScriptType obj);
|
||||||
|
|
||||||
public ScriptNumberLong Length()
|
public ScriptNumberLong Length()
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,5 +6,6 @@ namespace Upsilon.BaseTypes.ScriptTypeInterfaces
|
||||||
{
|
{
|
||||||
ScriptType GetValueFromIndex(ScriptType index);
|
ScriptType GetValueFromIndex(ScriptType index);
|
||||||
IEnumerator<ScriptType> GetScriptEnumerator();
|
IEnumerator<ScriptType> GetScriptEnumerator();
|
||||||
|
bool Contains(ScriptType obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -108,5 +108,11 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
return (from object key in Dictionary.Keys
|
return (from object key in Dictionary.Keys
|
||||||
select key.ToScriptType()).GetEnumerator();
|
select key.ToScriptType()).GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Contains(ScriptType obj)
|
||||||
|
{
|
||||||
|
var cSharpObj = obj.ToCSharpObject();
|
||||||
|
return Dictionary.Contains(cSharpObj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -138,6 +138,12 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Contains(ScriptType obj)
|
||||||
|
{
|
||||||
|
var cSharpObj = obj.ToCSharpObject();
|
||||||
|
return List.Contains(cSharpObj);
|
||||||
|
}
|
||||||
|
|
||||||
public ScriptNumberLong Length()
|
public ScriptNumberLong Length()
|
||||||
{
|
{
|
||||||
return new ScriptNumberLong(List.Count);
|
return new ScriptNumberLong(List.Count);
|
||||||
|
|
|
@ -12,14 +12,7 @@ namespace Upsilon.StandardLibraries
|
||||||
[ScriptFunction("contains", "Returns a boolean that defines whether a table contains a value", directScriptManipulation: true)]
|
[ScriptFunction("contains", "Returns a boolean that defines whether a table contains a value", directScriptManipulation: true)]
|
||||||
public ScriptBoolean Contains(IIterable table, ScriptType obj)
|
public ScriptBoolean Contains(IIterable table, ScriptType obj)
|
||||||
{
|
{
|
||||||
var enumerator = table.GetScriptEnumerator();
|
return table.Contains(obj);
|
||||||
while (enumerator.MoveNext())
|
|
||||||
{
|
|
||||||
var current = enumerator.Current;
|
|
||||||
if (current == obj)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[ScriptFunction("remove", "Removes an object from a table.", directScriptManipulation: true)]
|
[ScriptFunction("remove", "Removes an object from a table.", directScriptManipulation: true)]
|
||||||
|
|
Loading…
Reference in New Issue