Skip to content

Instantly share code, notes, and snippets.

@toptensoftware
Created October 26, 2016 03:40
Show Gist options
  • Save toptensoftware/e4f6b2035d4fc12482b52f8047aab271 to your computer and use it in GitHub Desktop.
Save toptensoftware/e4f6b2035d4fc12482b52f8047aab271 to your computer and use it in GitHub Desktop.
public interface IContext
{
double ResolveVariable(string name);
double CallFunction(string name, double[] arguments);
}
public class NodeFunctionCall : Node
{
public NodeFunctionCall(string functionName, Node[] arguments)
{
_functionName = functionName;
_arguments = arguments;
}
string _functionName;
Node[] _arguments;
public override double Eval(IContext ctx)
{
// Evaluate all arguments
var argVals = new double[_arguments.Length];
for (int i=0; i<_arguments.Length; i++)
{
argVals[i] = _arguments[i].Eval(ctx);
}
// Call the function
return ctx.CallFunction(_functionName, argVals);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment