コード例 #1
0
        public override Value ADividedByB(Value other, int otherType, Context context, bool isSelfLhs)
        {
            ExampleCustomVal val = other as ExampleCustomVal;

            if (val == null)
            {
                return(null);
            }

            return(new ExampleCustomVal(NumA / val.NumA, "???"));
        }
コード例 #2
0
        public override Value APlusB(Value other, int otherType, Context context, bool isSelfLhs)
        {
            ExampleCustomVal val = other as ExampleCustomVal;

            if (val == null)
            {
                return(null);
            }

            return(new ExampleCustomVal(NumA + val.NumA, StrB + val.StrB));
        }
コード例 #3
0
        public override double Equality(Value rhs, int recursionDepth = 16)
        {
            ExampleCustomVal rhsVal = rhs as ExampleCustomVal;

            if (rhsVal == null)
            {
                return(0);
            }

            if (NumA == rhsVal.NumA &&
                StrB == rhsVal.StrB)
            {
                return(1);
            }
            return(0);
        }
コード例 #4
0
        public override Value ATimesB(Value other, int otherType, Context context, bool isSelfLhs)
        {
            if (otherType == MiniscriptTypeInts.ValNumberTypeInt)
            {
                ValNumber valNum = other as ValNumber;
                if (valNum == null)
                {
                    return(null);
                }
                return(new ExampleCustomVal(NumA * (float)valNum.value, "???"));
            }

            ExampleCustomVal val = other as ExampleCustomVal;

            if (val == null)
            {
                return(null);
            }

            return(new ExampleCustomVal(NumA * val.NumA, "???"));
        }
コード例 #5
0
        public static void InitializeIntrinsics()
        {
            if (_hasStaticInit)
            {
                return;
            }
            _hasStaticInit = true;
            // Load the constructor
            Intrinsic ctor = Intrinsic.Create("ExampleCustom");

            ctor.AddParam(NumAValueName, 0.0);
            ctor.AddParam(StringBValueName, "");
            ctor.code = (context, partialResult) =>
            {
                ValNumber numA = context.GetVar(NumAValueName) as ValNumber;
                ValString strB = context.GetVar(StringBValueName) as ValString;

                ExampleCustomVal customVal = new ExampleCustomVal(
                    numA != null ? (float)numA.value : 0,
                    strB != null ? strB.value : "");

                return(new Intrinsic.Result(customVal));
            };

            _isPotatoFunction = Intrinsic.Create(IsPotatoFunction, false);
            _isPotatoFunction.AddParam("item");
            _isPotatoFunction.code = (context, partialResult) =>
            {
                ValString str = context.GetVar("item") as ValString;
                if (str != null && str.value == "potato")
                {
                    return(Intrinsic.Result.True);
                }
                return(Intrinsic.Result.False);
            };
        }