Ejemplo n.º 1
0
        public object EvaluatePlusExpression(SkryptObject left, SkryptObject right)
        {
            if (left is NumberInstance && right is NumberInstance)
            {
                return((left as NumberInstance) + (right as NumberInstance));
            }

            if (left is StringInstance)
            {
                return((left as StringInstance).Value + right);
            }

            if (right is StringInstance)
            {
                return(left + (right as StringInstance).Value);
            }

            if (left is VectorInstance && right is VectorInstance)
            {
                return(VectorInstance.ComponentMath(_engine, left as VectorInstance, right as VectorInstance, (x, y) => x + y));
            }

            if (left is NumberInstance && right is VectorInstance)
            {
                return(VectorInstance.ComponentMathNumeric(_engine, right as VectorInstance, (x) => (left as NumberInstance) + x));
            }

            if (left is VectorInstance && right is NumberInstance)
            {
                return(VectorInstance.ComponentMathNumeric(_engine, left as VectorInstance, (x) => x + (right as NumberInstance)));
            }

            return(new InvalidOperation());
        }
Ejemplo n.º 2
0
        public object EvaluateMultiplyExpression(SkryptObject left, SkryptObject right)
        {
            if (left is NumberInstance && right is NumberInstance)
            {
                return((left as NumberInstance) * (right as NumberInstance));
            }

            if (left is StringInstance && right is NumberInstance)
            {
                var str = (left as StringInstance).Value;
                var amt = (int)(right as NumberInstance).Value;

                return(new StringBuilder(str.Length * amt).Insert(0, str, amt).ToString());
            }

            if (left is VectorInstance && right is VectorInstance)
            {
                return(VectorInstance.ComponentMath(_engine, left as VectorInstance, right as VectorInstance, (x, y) => x * y));
            }

            if (left is NumberInstance && right is VectorInstance)
            {
                return(VectorInstance.ComponentMathNumeric(_engine, right as VectorInstance, (x) => (left as NumberInstance) * x));
            }

            if (left is VectorInstance && right is NumberInstance)
            {
                return(VectorInstance.ComponentMathNumeric(_engine, left as VectorInstance, (x) => x * (right as NumberInstance)));
            }

            if (left is ArrayInstance && right is NumberInstance)
            {
                var list = new List <SkryptObject>();

                for (int i = 0; i < (right as NumberInstance); i++)
                {
                    list.AddRange((left as ArrayInstance).SequenceValues);
                }

                var repeated = _engine.CreateArray(list.ToArray());
                repeated.Dictionary = (left as ArrayInstance).Dictionary;

                return(repeated);
            }

            return(new InvalidOperation());
        }
Ejemplo n.º 3
0
        public object EvaluateSubtractExpression(SkryptObject left, SkryptObject right)
        {
            if (left is NumberInstance && right is NumberInstance)
            {
                return((left as NumberInstance) - (right as NumberInstance));
            }

            if (left is VectorInstance && right is VectorInstance)
            {
                return(VectorInstance.ComponentMath(_engine, left as VectorInstance, right as VectorInstance, (x, y) => x - y));
            }

            if (left is VectorInstance && right is NumberInstance)
            {
                return(VectorInstance.ComponentMathNumeric(_engine, left as VectorInstance, (x) => x - (right as NumberInstance)));
            }

            return(new InvalidOperation());
        }