示例#1
0
文件: MondValue.cs 项目: SirTony/Mond
        /// <summary>
        /// Construct a new MondValue. Should only be used for Object or Array.
        /// </summary>
        private MondValue(MondValueType type)
        {
            _type        = type;
            _numberValue = 0;

            switch (type)
            {
            case MondValueType.Undefined:
            case MondValueType.Null:
            case MondValueType.True:
            case MondValueType.False:
                ObjectValue   = null;
                ArrayValue    = null;
                _stringValue  = null;
                FunctionValue = null;
                break;

            case MondValueType.Object:
                ArrayValue    = null;
                _stringValue  = null;
                FunctionValue = null;
                ObjectValue   = new VirtualMachine.Object();
                break;

            case MondValueType.Array:
                ObjectValue   = null;
                _stringValue  = null;
                FunctionValue = null;
                ArrayValue    = new List <MondValue>();
                break;

            default:
                throw new MondException("Incorrect MondValue constructor use");
            }
        }
示例#2
0
        /// <summary>
        /// Construct a new MondValue. Should only be used for Object or Array.
        /// </summary>
        public MondValue(MondValueType type)
            : this()
        {
            Type = type;

            switch (type)
            {
            case MondValueType.Undefined:
            case MondValueType.Null:
            case MondValueType.True:
            case MondValueType.False:
                break;

            case MondValueType.Object:
                ObjectValue = new VirtualMachine.Object();
                break;

            case MondValueType.Array:
                ArrayValue = new List <MondValue>();
                break;

            default:
                throw new MondException("Incorrect MondValue constructor use");
            }
        }
示例#3
0
文件: MondValue.cs 项目: SirTony/Mond
        /// <summary>
        /// Construct a new Number MondValue with the specified value.
        /// </summary>
        private MondValue(double value)
        {
            _type        = MondValueType.Number;
            _numberValue = value;

            ObjectValue   = null;
            ArrayValue    = null;
            _stringValue  = null;
            FunctionValue = null;
        }
示例#4
0
文件: MondValue.cs 项目: SirTony/Mond
        internal MondValue(Closure closure)
        {
            _type        = MondValueType.Function;
            _numberValue = 0;

            ObjectValue   = null;
            ArrayValue    = null;
            _stringValue  = null;
            FunctionValue = closure;
        }
示例#5
0
        private MondValue()
        {
            Type = MondValueType.Undefined;

            ObjectValue  = null;
            ArrayValue   = null;
            _numberValue = 0;
            _stringValue = null;

            FunctionValue = null;
        }
示例#6
0
        /// <summary>
        /// Construct a new Object MondValue with the specified values.
        /// </summary>
        public MondValue(IEnumerable <KeyValuePair <MondValue, MondValue> > values)
        {
            Type        = MondValueType.Object;
            ObjectValue = new VirtualMachine.Object();

            var obj = Object;

            foreach (var kvp in values)
            {
                obj.Add(kvp.Key, kvp.Value);
            }
        }
示例#7
0
文件: MondValue.cs 项目: SirTony/Mond
        /// <summary>
        /// Construct a new Function MondValue with the specified value. Instance functions will
        /// bind themselves to their parent object when being retrieved.
        /// </summary>
        private MondValue(MondInstanceFunction function)
        {
            if (ReferenceEquals(function, null))
            {
                throw new ArgumentNullException(nameof(function));
            }

            _type        = MondValueType.Function;
            _numberValue = 0;

            ObjectValue   = null;
            ArrayValue    = null;
            _stringValue  = null;
            FunctionValue = new Closure(function);
        }
示例#8
0
文件: MondValue.cs 项目: SirTony/Mond
        /// <summary>
        /// Construct a new String MondValue with the specified value.
        /// </summary>
        private MondValue(string value)
        {
            if (ReferenceEquals(value, null))
            {
                throw new ArgumentNullException(nameof(value));
            }

            _type        = MondValueType.String;
            _numberValue = 0;
            _stringValue = value;

            ObjectValue   = null;
            ArrayValue    = null;
            FunctionValue = null;
            _stringValue  = value;
        }
示例#9
0
文件: MondValue.cs 项目: foobit/Mond
 /// <summary>
 /// Construct a new Object MondValue and attach a MondState to it. Should be used if using metamethods.
 /// </summary>
 private MondValue(MondState state)
 {
     Type              = MondValueType.Object;
     ObjectValue       = new VirtualMachine.Object();
     ObjectValue.State = state;
 }