Пример #1
0
        public static ScriptVariable Add(this ScriptVariable self, ScriptVariable other)
        {
            if (self == null)
            {
                return(null);
            }
            other = ConvertTo(other, self.Type);
            switch (self.Type)
            {
            case ScriptVariableType.Boolean:
                if (other == null)
                {
                    return(null);
                }
                return(new BooleanVariable(self.ToBoolean() || other.ToBoolean()));

            case ScriptVariableType.List:
                List <ScriptVariable> list = new List <ScriptVariable>(self.ToList());
                if (other == null)
                {
                    list.Add(null);
                }
                else
                {
                    list.AddRange(other.ToList());
                }
                return(new ListVariable(list));

            case ScriptVariableType.Number:
                if (other == null)
                {
                    return(self.Clone());
                }
                try {
                    return(new NumberVariable(self.ToNumber() + other.ToNumber()));
                } catch (ArithmeticException ex) {
                    ScriptConsole.Singleton.Warn(ex.GetType().Name);
                    return(new NumberVariable(0));
                }

            /*
             * case ScriptVariableType.Object:
             * ScriptSub.Singleton.Warn("cannot add " + self.Type.ToString());
             * return self.Clone();
             */
            case ScriptVariableType.String:
                if (other == null)
                {
                    return(self.Clone());
                }
                return(new StringVariable(self.ToString() + other.ToString()));
            }
            return(null);
        }
Пример #2
0
 public override bool SetIndexedValue(int index, ScriptVariable value)
 {
     if (index < 0)
     {
         return(false);
     }
     if (index >= _value.Count)
     {
         while (_value.Count < index)
         {
             _value.Add(null);
         }
         _value.Add(value.Clone());
     }
     else
     {
         _value[index] = value.Clone();
     }
     return(true);
 }
Пример #3
0
        public static ScriptVariable Divide(this ScriptVariable self, ScriptVariable other)
        {
            if (self == null)
            {
                return(null);
            }
            other = ConvertTo(other, self.Type);
            switch (self.Type)
            {
            case ScriptVariableType.Boolean:
                if (other == null)
                {
                    return(null);
                }
                return(new BooleanVariable(self.ToBoolean() || !other.ToBoolean()));

            case ScriptVariableType.List:
            case ScriptVariableType.String:
                //case ScriptVariableType.Object:
                ScriptConsole.Singleton.Warn("cannot divide " + self.Type.ToString());
                return(self.Clone());

            case ScriptVariableType.Number:
                if (other == null)
                {
                    return(self.Clone());
                }
                try {
                    return(new NumberVariable(self.ToNumber() / other.ToNumber()));
                } catch (ArithmeticException ex) {
                    ScriptConsole.Singleton.Warn(ex.GetType().Name);
                    return(new NumberVariable(0));
                }
            }
            return(null);
        }