Adds basics of new list helper library

This commit is contained in:
Deukhoofd 2019-01-20 22:28:02 +01:00
parent b9183be4e7
commit 3737ac826c
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 26 additions and 0 deletions

View File

@ -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;
}
}
}

View File

@ -77,6 +77,11 @@ namespace Upsilon.StandardLibraries
boundFuncs.Add("math", boundFuncs.Add("math",
new UserDataVariableSymbol("math", BoundTypeHandler.GetTypeDefinition(typeof(MathLibrary)), true)); 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 scope = new EvaluationScope(funcs);
var boundScope = new BoundScope(boundFuncs, null); var boundScope = new BoundScope(boundFuncs, null);
return (scope, boundScope); return (scope, boundScope);