evalCallExpression method
Implementation
dynamic evalCallExpression(
CallExpression expression, Map<String?, dynamic> context) {
// olajos - March 14, 2022 - Added Functionality to Convert a.b() to _call call with parameters id, function, list<arguments>
// olajos - Modified January 26, 2023 - Added isVariable to capture dot notated executes like GLOBAL.x.set('value') or <id>.<subproperty>.set('red');
MemberExpression? exp = (expression.callee is MemberExpression)
? (expression.callee as MemberExpression)
: null;
if (exp != null && isVariable(exp.object) && expression.arguments is List) {
// evaluate id. id may be a bindable
String id = (expression.callee as MemberExpression).object.toString();
if (id.startsWith("___V") &&
context.containsKey(id) &&
(context[id] is String)) id = context[id];
// evaluate function. function may be a bindable
String fn = (expression.callee as MemberExpression).property.toString();
if (fn.startsWith("___V") &&
context.containsKey(fn) &&
(context[fn] is String)) fn = context[fn];
expression =
CallExpression(Variable(Identifier("execute")), expression.arguments);
var callee = eval(expression.callee, context);
var arguments =
expression.arguments!.map((e) => eval(e, context)).toList();
final List<dynamic> args = [id, fn, arguments];
return Function.apply(callee, args);
} else {
var callee = eval(expression.callee, context);
var arguments =
expression.arguments!.map((e) => eval(e, context)).toList();
return Function.apply(callee, arguments);
}
}