/// <summary> /// Sets the value at the given index in the 1D array held by this object. /// </summary> /// <param name="index">The array index.</param> /// <param name="right">The value of the index.</param> public void ArraySet(int index, TsObject right) { if (index < 0) { throw new ArgumentOutOfRangeException("index"); } if (Type != VariableType.Array1) { Type = VariableType.Array1; var temp = new TsObject[index + 1]; temp[index] = right; Value = new TsMutableValue <TsObject[]>(temp); return; } var self = (TsMutableValue <TsObject[]>)Value; var arr = self.StrongValue; if (index >= arr.Length) { var temp = new TsObject[index + 1]; Array.Copy(arr, 0, temp, 0, arr.Length); arr = temp; self.StrongValue = temp; } arr[index] = right; }
/// <summary> /// Sets the value at the given indeces in the 2D array held by this object. /// </summary> /// <param name="index1">The index of the first dimension.</param> /// <param name="index2">The index of the second dimension.</param> /// <param name="right">The value of the index.</param> public void ArraySet(int index1, int index2, TsObject right) { if (index1 < 0 || index2 < 0) { throw new ArgumentOutOfRangeException($"{(index1 < 0 ? nameof(index1) : nameof(index2))}"); } if (Type != VariableType.Array2) { Type = VariableType.Array2; var temp = new TsObject[index1 + 1][]; var inner = new TsObject[index2 + 1]; inner[index2] = right; temp[index1] = inner; Value = new TsMutableValue <TsObject[][]>(temp); return; } var self = (TsMutableValue <TsObject[][]>)Value; if (index1 >= self.StrongValue.Length) { var temp = new TsObject[index1 + 1][]; Array.Copy(self.StrongValue, 0, temp, 0, self.StrongValue.Length); self.StrongValue = temp; } if (self.StrongValue[index1] == null) { self.StrongValue[index1] = new TsObject[index2 + 1]; } else if (index2 >= self.StrongValue[index1].Length) { var temp = new TsObject[index2 + 1]; Array.Copy(self.StrongValue[index1], 0, temp, 0, self.StrongValue[index1].Length); self.StrongValue[index1] = temp; } self.StrongValue[index1][index2] = right; }
/// <summary> /// Creates a TaffyScript object from a ushort. /// </summary> /// <param name="value">The value of the object.</param> public TsObject(ushort value) { Type = VariableType.Real; Value = new TsImmutableValue <float>(value); }
/// <summary> /// Creates a string TaffyScript object from a char. /// </summary> /// <param name="value"></param> public TsObject(char value) { Type = VariableType.String; Value = new TsImmutableValue <string>(value.ToString()); }
private TsObject(VariableType type, ITsValue value) { Type = type; Value = value; }
/// <summary> /// Creates a TaffyScript object from a bool. /// </summary> /// <param name="value">The value of the object.</param> public TsObject(bool value) { Type = VariableType.Real; Value = new TsImmutableValue <float>(value ? 1 : 0); }
/// <summary> /// Creates a TaffyScript object from a <see cref="TsDelegate"/>. /// </summary> /// <param name="script">The value of the object.</param> public TsObject(TsDelegate script) { Type = VariableType.Delegate; Value = new TsImmutableValue <TsDelegate>(script); }
/// <summary> /// Creates a TaffyScript object from a 2D array. /// </summary> /// <param name="array">The value of the object.</param> public TsObject(TsObject[][] array) { Type = VariableType.Array2; Value = new TsMutableValue <TsObject[][]>(array); }
/// <summary> /// Creates a TaffyScript object from an instances id. /// </summary> /// <param name="instance">The instance to get the id from.</param> public TsObject(ITsInstance instance) { Type = VariableType.Instance; Value = new TsImmutableValue <ITsInstance>(instance); }
/// <summary> /// Creates a TaffyScript object from a string. /// </summary> /// <param name="value">The value of the object.</param> public TsObject(string value) { Type = VariableType.String; Value = new TsImmutableValue <string>(value); }
/// <summary> /// Creates a TaffyScript object from a double. /// </summary> /// <param name="value">The value of the object.</param> public TsObject(double value) { Type = VariableType.Real; Value = new TsImmutableValue <float>((float)value); }