Beispiel #1
0
    public void Arith(ArithOp op)
    {
        LuaValue a, b;

        b = LuaStack.Pop();

        if (op != ArithOp.Unm && op != ArithOp.Bnot)
        {
            a = LuaStack.Pop();
        }
        else
        {
            a = b;
        }

        var aop    = global::Arith.Operators[(int)op];
        var result = ArithSub(a, b, aop);

        if (result.Value != null)
        {
            LuaStack.Push(result);
            return;
        }

        string mm = aop.Metamethod;

        if (LuaValue.TryCallMetamethod(a, b, mm, this, out LuaValue metaRes))
        {
            LuaStack.Push(metaRes);
            return;
        }

        throw new LuaException("arithmetic error!");
Beispiel #2
0
    private static void BinaryArith(Instruction i, ILuaVM vm, ArithOp op)
    {
        var(a, b, c) = i.ABC();
        a           += 1;

        vm.GetRK(b);
        vm.GetRK(c);
        vm.Arith(op);
        vm.Replace(a);
    }
Beispiel #3
0
    private static void UnaryArith(Instruction i, ILuaVM vm, ArithOp op)
    {
        var(a, b, _) = i.ABC();
        a           += 1;
        b           += 1;

        vm.PushValue(b);
        vm.Arith(op);
        vm.Replace(a);
    }
        public static ArrayList ArithmeticOperation(double num1, double num2, ArithOp oper)
        {
            ArrayList result = new ArrayList();

            result.Add(false);
            result.Add(0);
            bool isEverythingOk = true;

            Arithmetic operation = null;

            switch (oper)
            {
            case ArithOp.Add:
                operation = (x, y) => { return(x + y); };
                break;

            case ArithOp.Sub:
                operation = (x, y) => { return(x - y); };
                break;

            case ArithOp.Mul:
                operation = (x, y) => { return(x * y); };
                break;

            case ArithOp.Div:
                operation = (x, y) =>
                {
                    if (y != 0)
                    {
                        return(x / y);
                    }
                    else
                    {
                        isEverythingOk = false;
                        return(0);
                    }
                };
                break;
            }

            if (operation != null)
            {
                result[1] = operation(num1, num2);
                result[0] = isEverythingOk;
            }

            return(result);
        }
Beispiel #5
0
 public UnaryOp(ArithOp op)
     : base(1)
 {
     this.op = op;
 }
Beispiel #6
0
 public BinaryOp(ArithOp op, bool overflow, bool unsigned)
     : base(1)
 {
     this.op = op;
     this.overflow = overflow;
     this.unsigned = unsigned;
 }
Beispiel #7
0
 private void SetLoopType(object nextToken)
 {
     if (nextToken is string && (string)nextToken == "up")
         _loopType = ArithOp.Up;
     else
         _loopType = ArithOp.Down;
 }