Created
October 26, 2016 03:40
-
-
Save toptensoftware/e4f6b2035d4fc12482b52f8047aab271 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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