예제 #1
0
        /// <inheritdoc />
        public virtual IMoValue Get(MoPath key, MoParams parameters)
        {
            if (key.HasChildren)
            {
                string main = key.Value;

                if (!string.IsNullOrWhiteSpace(main))
                {
                    IMoValue value = null;

                    if (!Map.TryGetValue(main, out value))
                    {
                        return(DoubleValue.Zero);
                    }

                    if (value is IMoStruct moStruct)
                    {
                        return(moStruct.Get(key.Next, parameters));
                    }

                    return(value);
                }
            }

            if (Map.TryGetValue(key.Value, out var v))
            {
                return(v);
            }

            return(DoubleValue.Zero);
        }
예제 #2
0
        /// <inheritdoc />
        public IMoValue Get(MoPath key, MoParams parameters)
        {
            if (key.HasChildren)
            {
                string main = key.Value;

                if (!string.IsNullOrWhiteSpace(main))
                {
                    ExecuteGet(key, main, parameters, out var value);

                    if (value is IMoStruct moStruct)
                    {
                        return(moStruct.Get(key.Next, parameters));
                    }

                    return(value);
                }
            }

            if (!ExecuteGet(key, key.Value, parameters, out var returnValue))
            {
                Debug.WriteLine($"({_instance.ToString()}) Unknown query: {key}");
            }

            return(returnValue);
        }
예제 #3
0
        /// <inheritdoc />
        public IMoValue Get(MoPath key, MoParams parameters)
        {
            if (Functions.TryGetValue(key.Value, out var func))
            {
                return(MoValue.FromObject(func(parameters)));
            }

            return(DoubleValue.Zero);
        }
예제 #4
0
        /// <inheritdoc />
        public IMoValue Get(MoPath key, MoParams parameters)
        {
            if (int.TryParse(key.Value, out int index))
            {
                return(this[index]);
            }

            throw new MoLangRuntimeException($"Invalid path for array access: {key.Path.ToString()}");
        }
예제 #5
0
        private bool ExecuteGet(MoPath property, string main, MoParams parameters, out IMoValue returnValue)
        {
            if (_propertyCache.Properties.TryGetValue(main, out var accessor))
            {
                if (!accessor.CanRead)
                {
                    throw new MoLangRuntimeException($"Cannot read from property '{property.ToString()}'", null);
                }

                returnValue = accessor.Get(_instance);
                return(true);
            }

            if (_propertyCache.Functions.TryGetValue(main, out var f))
            {
                returnValue = f.Invoke(_instance, parameters);
                return(true);
            }

            returnValue = DoubleValue.Zero;
            return(false);
        }
예제 #6
0
 public void DebugOutput(MoParams mo)
 {
     //  var str = string.Join(" ", mo.GetParams().Select(x => x?.AsString()));
     //  Console.WriteLine(str);
 }