First you will need a reference to the default ExpressionParser
var ep = ExpressionParserFactory.GetExpressionParser();
Then register a function that takes 3 parameters:
ep.RegisterFunction("Lerp", DoLerp, 3);
Finally write the DoLerp method referenced above.
private static void DoLerp(Stack<IOperand> stack, IBackingStore backingStore, long paramCount)
{
// Pop the correct number of parameters from the operands stack, ** in reverse order **
// If an operand is a variable, it is resolved from the backing store provided
IOperand third = OperatorActions.PopAndResolve(operands, backingStore);
IOperand second = OperatorActions.PopAndResolve(operands, backingStore);
IOperand first = OperatorActions.PopAndResolve(operands, backingStore);
float a = Convert.ToSingle(first.GetValue());
float b = Convert.ToSingle(second.GetValue());
float t = Convert.ToSingle(third.GetValue());
// The result is of type float
float result = a + t * (b - a);
// Push the result back onto the operand stack
stack.Push(new Operand(-1, OperandType.Float, result));
}
Aliases
Get a reference to the default ExpressionParser:
var ep = ExpressionParserFactory.GetExpressionParser();
Then register a new operator and use the existing matrix for &&
var ep = ExpressionParserFactory.GetExpressionParser();
Then simply register the overload like this
// Overload that will allow a long to be appended to a string
// To add a string to a long you'll need to add another overload
ep.RegisterOverload("+", OperandType.String, OperandType.Long,
(left, right) => new Operand(OperandType.String, (string)left.GetValue() + ((long)right.GetValue()).ToString()));
and to add a string to a long:
// Overload that will allow a string to be appended to a long
// To add a long to a string you'll need to add another overload
ep.RegisterOverload("+", OperandType.Long, OperandType.String,
(left, right) => new Operand(OperandType.String, (long)left.GetValue() + ((string)right.GetValue()).ToString()));
Putting the above into action, you can then start to really have some fun