diff --git a/Upsilon/StandardLibraries/ListLibrary.cs b/Upsilon/StandardLibraries/ListLibrary.cs new file mode 100644 index 0000000..927164c --- /dev/null +++ b/Upsilon/StandardLibraries/ListLibrary.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/Upsilon/StandardLibraries/StaticScope.cs b/Upsilon/StandardLibraries/StaticScope.cs index 4784c2c..7b825aa 100644 --- a/Upsilon/StandardLibraries/StaticScope.cs +++ b/Upsilon/StandardLibraries/StaticScope.cs @@ -77,6 +77,11 @@ namespace Upsilon.StandardLibraries boundFuncs.Add("math", new UserDataVariableSymbol("math", BoundTypeHandler.GetTypeDefinition(typeof(MathLibrary)), true)); + UserDataTypeHandler.LoadType(); + 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);