/// <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"); } }
/// <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"); } }
/// <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; }
internal MondValue(Closure closure) { _type = MondValueType.Function; _numberValue = 0; ObjectValue = null; ArrayValue = null; _stringValue = null; FunctionValue = closure; }
private MondValue() { Type = MondValueType.Undefined; ObjectValue = null; ArrayValue = null; _numberValue = 0; _stringValue = null; FunctionValue = null; }
/// <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); } }
/// <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); }
/// <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; }
/// <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; }