コード例 #1
0
        public override ILuaValue Arithmetic(BinaryOperationType type, LuaNumber self)
        {
            // Cannot use DefaultArithmetic since self and this are swapped.
            switch (type)
            {
            case BinaryOperationType.Add:
                return(new LuaNumber(self.Value + Value));

            case BinaryOperationType.Subtract:
                return(new LuaNumber(self.Value - Value));

            case BinaryOperationType.Multiply:
                return(new LuaNumber(self.Value * Value));

            case BinaryOperationType.Divide:
                return(new LuaNumber(self.Value / Value));

            case BinaryOperationType.Power:
                return(new LuaNumber(Math.Pow(self.Value, Value)));

            case BinaryOperationType.Modulo:
                return(new LuaNumber(self.Value - Math.Floor(self.Value / Value) * Value));

            case BinaryOperationType.Concat:
                return(new LuaString(self.ToString() + ToString()));

            case BinaryOperationType.Gt:
                return(LuaBoolean.Create(self.CompareTo(this) > 0));

            case BinaryOperationType.Lt:
                return(LuaBoolean.Create(self.CompareTo(this) < 0));

            case BinaryOperationType.Gte:
                return(LuaBoolean.Create(self.CompareTo(this) >= 0));

            case BinaryOperationType.Lte:
                return(LuaBoolean.Create(self.CompareTo(this) <= 0));

            case BinaryOperationType.Equals:
                return(LuaBoolean.Create(self.Equals(this)));

            case BinaryOperationType.NotEquals:
                return(LuaBoolean.Create(!self.Equals(this)));

            case BinaryOperationType.And:
                return(!self.IsTrue ? self : this);

            case BinaryOperationType.Or:
                return(self.IsTrue ? self : this);

            default:
                throw new ArgumentException(Resources.BadBinOp);
            }
        }
コード例 #2
0
ファイル: LuaString.cs プロジェクト: fourst4r/ModMaker.Lua
        /// <summary>
        /// Performs a binary arithmetic operation and returns the result.
        /// </summary>
        /// <param name="type">The type of operation to perform.</param>
        /// <param name="self">The first value to use.</param>
        /// <returns>The result of the operation.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// If the operation cannot be performed with the given values.
        /// </exception>
        /// <exception cref="System.InvalidArgumentException">
        /// If the argument is an invalid value.
        /// </exception>
        public override ILuaValue Arithmetic(BinaryOperationType type, LuaNumber self)
        {
            var t = this.ToNumber();

            if (t != null)
            {
                return(t.Arithmetic(type, self));
            }
            else
            {
                throw new InvalidOperationException(Errors.CannotArithmetic(LuaValueType.String));
            }
        }
コード例 #3
0
 /// <summary>
 /// Performs a binary arithmetic operation and returns the result.
 /// </summary>
 /// <param name="type">The type of operation to perform.</param>
 /// <param name="self">The first value to use.</param>
 /// <returns>The result of the operation.</returns>
 /// <exception cref="System.InvalidOperationException">
 /// If the operation cannot be performed with the given values.
 /// </exception>
 /// <exception cref="System.InvalidArgumentException">
 /// If the argument is an invalid value.
 /// </exception>
 ILuaValue ILuaValueVisitor.Arithmetic(BinaryOperationType type, LuaNumber self)
 {
     throw new InvalidOperationException(Errors.CannotArithmetic(LuaValueType.Function));
 }
コード例 #4
0
 /// <summary>
 /// Performs a binary arithmetic operation and returns the result.
 /// </summary>
 /// <param name="type">The type of operation to perform.</param>
 /// <param name="self">The first value to use.</param>
 /// <returns>The result of the operation.</returns>
 /// <exception cref="System.InvalidOperationException">
 /// If the operation cannot be performed with the given values.
 /// </exception>
 /// <exception cref="System.InvalidArgumentException">
 /// If the argument is an invalid value.
 /// </exception>
 public override ILuaValue Arithmetic(BinaryOperationType type, LuaNumber self)
 {
     return(self.Arithmetic(type, values_[0]));
 }
コード例 #5
0
 public ILuaValue ArithmeticFrom(BinaryOperationType type, LuaNumber self)
 {
     throw new NotImplementedException();
 }
コード例 #6
0
ファイル: LuaValueBase.cs プロジェクト: fourst4r/ModMaker.Lua
 /// <summary>
 /// Performs a binary arithmetic operation and returns the result.
 /// </summary>
 /// <param name="type">The type of operation to perform.</param>
 /// <param name="self">The first value to use.</param>
 /// <returns>The result of the operation.</returns>
 /// <exception cref="System.InvalidOperationException">
 /// If the operation cannot be performed with the given values.
 /// </exception>
 /// <exception cref="System.InvalidArgumentException">
 /// If the argument is an invalid value.
 /// </exception>
 public virtual ILuaValue Arithmetic(BinaryOperationType type, LuaNumber self)
 {
     throw new InvalidOperationException(Errors.CannotArithmetic(this.ValueType));
 }