Example #1
0
        public static TotemValue Push(TotemValue array, TotemArguments parameters)
        {
            TotemArray arr = (TotemArray)array;

            arr.value.Add(parameters.Value(0));
            return(arr);
        }
Example #2
0
 public static TotemValue Filter(TotemValue array, TotemArguments parameters)
 {
     TotemArray newArr = new TotemArray();
     TotemArray arr = (TotemArray)array;
     TotemValue fn = parameters.Value(0);
     foreach (var itm in arr.value)
     {
         var arguments = new TotemArguments();
         arguments.Add(null, itm);
         if ((bool)fn.Execute(arguments))
             newArr.AddItem(itm);
     }
     return newArr;
 }
Example #3
0
        public static TotemValue Filter(TotemValue array, TotemArguments parameters)
        {
            TotemArray newArr = new TotemArray();
            TotemArray arr    = (TotemArray)array;
            TotemValue fn     = parameters.Value(0);

            foreach (var itm in arr.value)
            {
                var arguments = new TotemArguments();
                arguments.Add(null, itm);
                if ((bool)fn.Execute(arguments))
                {
                    newArr.AddItem(itm);
                }
            }
            return(newArr);
        }
Example #4
0
        public static object GetFunctionParametersValue(TotemFunction function, int index, string name, TotemArray extraArgs, TotemDictionary dict)
        {
            object val;
            if (extraArgs != null && extraArgs.Count > 0)
                return extraArgs.Shift();

            if (dict != null && dict.TryRemoveValue(name, out val))
                return val;

            return function.Defaults[index];
        }
Example #5
0
        public static object ExtractParamsArgument(TotemFunction function, int argCnt, TotemArray list)
        {
            if (list.Count != 0)
                return list.Shift();

            throw function.BadArgumentError(argCnt);
        }
Example #6
0
        public static object ExtractAnyArgument(TotemFunction function, string name, int argCnt, TotemArray list, IDictionary dict)
        {
            object val;
            if (dict.Contains(name))
            {
                if (list.Count != 0)
                    throw MultipleKeywordArgumentError(function, name);

                val = dict[name];
                dict.Remove(name);
                return val;
            }

            if(list.Count != 0)
            {
                return list.Shift();
            }

            if (function.ExpandListPosition == -1 && dict.Count > 0)
            {
                // Totem raises an error for extra splatted kw keys before missing arguments.
                // Therefore we check for this in the error case here.
                foreach (string x in dict.Keys)
                {
                    bool found = false;
                    foreach (string y in function.ArgNames)
                    {
                        if (x == y)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                        throw UnexpectedKeywordArgumentError(function, x);
                }
            }

            throw BinderOps.TypeErrorForIncorrectArgumentCount(
                function.Name,
                function.NormalArgumentCount,
                function.Defaults.Length,
                argCnt,
                function.ExpandListPosition != -1,
                dict.Count > 0
            );
        }
Example #7
0
 public static void AddParamsArguments(TotemArray list, params object[] args)
 {
     for (int i = 0; i < args.Length; i++)
         list.Insert(i, args[i]);
 }