Adds basics of new list helper library
This commit is contained in:
parent
b9183be4e7
commit
3737ac826c
|
@ -0,0 +1,21 @@
|
|||
using Upsilon.BaseTypes;
|
||||
using Upsilon.BaseTypes.ScriptTypeInterfaces;
|
||||
|
||||
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)
|
||||
{
|
||||
var enumerator = table.GetScriptEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
var current = enumerator.Current;
|
||||
if (current == obj)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -77,6 +77,11 @@ namespace Upsilon.StandardLibraries
|
|||
boundFuncs.Add("math",
|
||||
new UserDataVariableSymbol("math", BoundTypeHandler.GetTypeDefinition(typeof(MathLibrary)), true));
|
||||
|
||||
UserDataTypeHandler.LoadType<ListLibrary>();
|
||||
funcs.Add("list", new ListLibrary().ToScriptType());
|
||||
boundFuncs.Add("list",
|
||||
new UserDataVariableSymbol("list", BoundTypeHandler.GetTypeDefinition(typeof(ListLibrary)), true));
|
||||
|
||||
var scope = new EvaluationScope(funcs);
|
||||
var boundScope = new BoundScope(boundFuncs, null);
|
||||
return (scope, boundScope);
|
||||
|
|
Loading…
Reference in New Issue