Beispiel #1
0
        /// <summary>
        /// = array[index1][index2][...][indexN], and
        /// indices = {index1, index2, ..., indexN}
        /// </summary>
        /// <param name="array"></param>
        /// <param name="indices"></param>
        /// <param name="core"></param>
        /// <returns></returns>
        public static StackValue GetValueFromIndices(StackValue array, List <StackValue> indices, RuntimeCore runtimeCore)
        {
            if (indices.Count == 0)
            {
                return(array);
            }
            else if (!array.IsArray && !array.IsString)
            {
                runtimeCore.RuntimeStatus.LogWarning(WarningID.kOverIndexing, Resources.kArrayOverIndexed);
                return(StackValue.Null);
            }

            StackValue[][] zippedIndices = ArrayUtils.GetZippedIndices(indices, runtimeCore);
            if (zippedIndices == null || zippedIndices.Length == 0)
            {
                return(StackValue.Null);
            }

            StackValue[] values = new StackValue[zippedIndices.Length];
            for (int i = 0; i < zippedIndices.Length; ++i)
            {
                values[i] = GetValueFromIndices(array, zippedIndices[i], runtimeCore);
            }

            if (zippedIndices.Length > 1)
            {
                if (array.IsString)
                {
                    string result = string.Join(string.Empty, values.Select(v => runtimeCore.RuntimeMemory.Heap.GetString(v)));
                    return(runtimeCore.RuntimeMemory.Heap.AllocateString(result));
                }
                else
                {
                    return(runtimeCore.RuntimeMemory.Heap.AllocateArray(values, null));
                }
            }
            else
            {
                return(values[0]);
            }
        }