/// <summary> /// Call a function by passing in all the values. /// </summary> /// <param name="ctx">The context of the runtime</param> /// <param name="functionName">The name of the function to call.</param> /// <param name="paramListExpressions">List of parameters as expressions to evaluate first to actual values</param> /// <param name="paramVals">List to store the resolved paramter expressions. ( these will be resolved if paramListExpressions is supplied and resolveParams is true. If /// resolveParams is false, the list is assumed to have the values for the paramters to the function.</param> /// <param name="resolveParams">Whether or not to resolve the list of parameter expression objects</param> /// <returns></returns> public static object CallFunctionInScript(Context ctx, IAstVisitor visitor, string functionName, FunctionExpr function, List <Expr> paramListExpressions, List <object> paramVals, bool resolveParams) { // 1. Determine if any parameters provided. var hasParams = paramListExpressions != null && paramListExpressions.Count > 0; // 2. Resolve parameters if necessary var hasArguments = function.Meta.HasArguments(); if (resolveParams && function != null && (hasArguments || hasParams)) { ParamHelper.ResolveParametersForScriptFunction(function.Meta, paramListExpressions, paramVals, visitor); } // 3. Assign the argument values to the function and evaluate. function.ArgumentValues = paramVals; visitor.VisitFunction(function); object result = null; if (function.HasReturnValue) { result = function.ReturnValue; } else { result = LObjects.Null; } return(result); }
/// <summary> /// Call a function by passing in all the values. /// </summary> /// <param name="ctx">The context of the runtime</param> /// <param name="functionName">The name of the function to call.</param> /// <param name="paramListExpressions">List of parameters as expressions to evaluate first to actual values</param> /// <param name="paramVals">List to store the resolved paramter expressions. ( these will be resolved if paramListExpressions is supplied and resolveParams is true. If /// resolveParams is false, the list is assumed to have the values for the paramters to the function.</param> /// <param name="resolveParams">Whether or not to resolve the list of parameter expression objects</param> /// <returns></returns> public static object CallFunctionInScript(Context ctx, string functionName, List <Expr> paramListExpressions, List <object> paramVals, bool resolveParams) { // 1. Get the function definition var function = ctx.Functions.GetByName(functionName); // 2. Determine if any parameters provided. var hasParams = paramListExpressions != null && paramListExpressions.Count > 0; // 3. Resolve parameters if necessary if (resolveParams && function != null && (function.HasArguments || hasParams)) { ParamHelper.ResolveParametersForScriptFunction(function.Meta, paramListExpressions, paramVals); } // 4. Assign the argument values to the function and evaluate. function.ArgumentValues = paramVals; function.Evaluate(); object result = null; if (function.HasReturnValue) { result = function.ReturnValue; } else { result = LObjects.Null; } return(result); }