Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
        /// <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;
        }
Exemplo n.º 3
0
 /// <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);
 }
Exemplo n.º 4
0
 /// <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());
 }
Exemplo n.º 5
0
 private TsObject(VariableType type, ITsValue value)
 {
     Type  = type;
     Value = value;
 }
Exemplo n.º 6
0
 /// <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);
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
0
 /// <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);
 }
Exemplo n.º 9
0
 /// <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);
 }
Exemplo n.º 10
0
 /// <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);
 }
Exemplo n.º 11
0
 /// <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);
 }