eval method

dynamic eval({
  1. String key = "",
  2. Expression? exp,
})

Evaluates an expression using the current variables. If exp is provided, it evaluates that specific expression, otherwise it uses the key to look up an expression.d to extract variables from the valuta field.

Implementation

dynamic eval({String key = "", Expression? exp}) {
  late Expression torun;
  if (exp != null) {
    torun = exp;
  } else if (expressions.containsKey(key)) {
    torun = expressions[key];
  } else {
    //print("neither $key nor $exp bailing");
    return (-1);
  }

  final evaluator = const ExpressionEvaluator();
  var r = evaluator.eval(torun, vars);
  print("evaled result = '$r'");
  return (r);
}