Esempio n. 1
0
        public static void ArrayMatchVal(OpCodeData data)
        {
            var pattern = data.RuntimeStack.PopStr();
            var array = data.RuntimeStack.Pop(MuftecType.List, MuftecType.Dictionary);

            MuftecDict origDict;

            if (array.Type == MuftecType.List)
            {
                origDict = ((MuftecList)array.Item).ToDict();
            }
            else if (array.Type == MuftecType.Dictionary)
            {
                origDict = ((MuftecDict)array.Item);
            }
            else
            {
                throw new MuftecInvalidStackItemTypeException(data.RuntimeStack);
            }

            var newDict = new MuftecDict();

            foreach (var item in origDict)
            {
                if (SharedUtil.smatch(item.Value.ToString(), pattern))
                {
                    newDict.Add(item.Key, item.Value);
                }
            }

            data.RuntimeStack.Push(newDict);
        }
Esempio n. 2
0
        public static void ArrayMakeDict(OpCodeData data)
        {
            var count = data.RuntimeStack.PopInt();

            var dict = new MuftecDict(count);
            for (var i = 0; i < count; i++)
            {
                var key = data.RuntimeStack.Pop();
                var val = data.RuntimeStack.Pop();
                dict.Add(key, val);
            }

            data.RuntimeStack.Push(dict);
        }