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, "???")); }
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)); }
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); }
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, "???")); }
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); }; }