/// <summary> /// Call a fluent script function from c#. /// </summary> /// <param name="context">The context of the call.</param> /// <param name="expr">The lambda function</param> /// <param name="convertApplicableTypes">Whether or not to convert applicable c# types to fluentscript types, eg. ints and longs to double, List(object) to LArrayType and Dictionary(string, object) to LMapType</param> /// <param name="args"></param> public static object CallFunctionViaCSharpUsingLambda(Context context, FunctionExpr expr, bool convertApplicableTypes, params object[] args) { var argsList = args.ToList<object>(); if (convertApplicableTypes) LangTypeHelper.ConvertToLangTypeValues(argsList); var execution = new Execution(); execution.Ctx = context; if (EvalHelper.Ctx == null) EvalHelper.Ctx = context; var result = FunctionHelper.CallFunctionInScript(context, execution, expr.Meta.Name, expr, null, argsList, false); return result; }
/// <summary> /// Executes the script /// </summary> /// <param name="script">Script text</param> /// <param name="clearExistingCode">Whether or not to clear existing parsed code and start fresh.</param> public void Execute(string script, bool clearExistingCode, bool resetScript, params IPhase[] phases) { this.InitPlugins(); if(_parser != null) { var execution = new Execution(); execution.Ctx = _context; EvalHelper.Ctx = _context; _parser.OnDemandEvaluator = execution; } var phaseExecutor = new PhaseExecutor(); // 1. Create the execution phase if (clearExistingCode || _phaseCtx == null) { _phaseCtx = new PhaseContext(); _phaseCtx.Ctx = _context; } if (resetScript) { _phaseCtx.ScriptText = script; } var phasesList = phases.ToList(); var result = phaseExecutor.Execute(script, _phaseCtx, _context, phasesList); this._runResult = result.Result; }