コード例 #1
0
        public int IntValue()
        {
            switch (Type)
            {
            case BurikoValueType.Int:
            case BurikoValueType.Bool:
                return(valueInt);

            case BurikoValueType.String:
                if (int.TryParse(valueString, out int result))
                {
                    return(result);
                }
                throw new Exception("BurikoValue: Cannot parse type string into type int.");

            case BurikoValueType.Variable:
            {
                IBurikoObject memory = BurikoMemory.Instance.GetMemory(valueReference.Property);
                return(memory.IntValue(valueReference));
            }

            case BurikoValueType.Operation:
                return(valueVariable.IntValue());

            case BurikoValueType.Null:
                return(0);

            default:
                throw new NotImplementedException($"BurikoValue: Cannot cast type {Type} into type Int.");
            }
        }
コード例 #2
0
        private static int PerformMath(BurikoMathType type, BurikoVariable a, BurikoVariable b)
        {
            int num  = a.IntValue();
            int num2 = b.IntValue();

            switch (type)
            {
            case BurikoMathType.Equals:
                return((num == num2) ? 1 : 0);

            case BurikoMathType.Add:
                return(num + num2);

            case BurikoMathType.Divide:
                return(num / num2);

            case BurikoMathType.Multiply:
                return(num * num2);

            case BurikoMathType.Subtract:
                return(num - num2);

            case BurikoMathType.GreaterThan:
                return((num > num2) ? 1 : 0);

            case BurikoMathType.GreaterThanOrEquals:
                return((num >= num2) ? 1 : 0);

            case BurikoMathType.LessThan:
                return((num < num2) ? 1 : 0);

            case BurikoMathType.LessThanOrEquals:
                return((num <= num2) ? 1 : 0);

            case BurikoMathType.Modulus:
                return(num % num2);

            case BurikoMathType.NotEquals:
                return((num != num2) ? 1 : 0);

            case BurikoMathType.And:
                return((num != 0 && num2 != 0) ? 1 : 0);

            case BurikoMathType.Or:
                return((num != 0 || num2 != 0) ? 1 : 0);

            default:
                throw new Exception("Cannot find a handler for math type " + type);
            }
        }