runner function

(bool, LuaObject) runner(
  1. AST ast, {
  2. required EvaluatorMixin constructor(),
  3. RunnerErrorsCallback? onErrors,
})

Creates an evaluator satisfying EvaluatorMixin via constructor. Then passes ast into EvaluatorMixin.visitAST to parse and evaluate the scriptlet or program.

Returns a tuple (bool, LuaObject) containing the result, if any. If there was an error returns a tuple (false, LuaObject.nil). Additionally, the onErrors callback will be invoked with those errors. If the result would be null, then returns an instance of LuaObject.nil.

Implementation

(bool, LuaObject) runner(
  AST ast, {
  required EvaluatorMixin Function() constructor,
  RunnerErrorsCallback? onErrors,
}) {
  final eval = constructor.call();
  final out = eval.visitAST(ast);

  if (eval.errors.isNotEmpty) {
    onErrors?.call(eval.errors);
    return (false, LuaObject.nil('out'));
  }

  return (true, out?.toLua('out') ?? LuaObject.nil('out'));
}