init method

  1. @override
void init(
  1. BallEngine engine
)
override

Called once by BallEngine during construction, before any program statements are evaluated. Override to capture engine state (e.g. BallEngine.stdout) or to lazily build dispatch tables.

Implementation

@override
void init(BallEngine engine) {
  // _buildStdDispatch lives in BallEngine so it can close over all the
  // engine helper methods (same Dart library → library-private access).
  final full = engine._buildStdDispatch();
  final allowlist = _allowlist;
  // Add built-ins using putIfAbsent so that:
  //   • functions pre-registered via register() are NOT overwritten.
  //   • functions pre-removed via unregister() (_tombstones) are skipped.
  for (final entry in full.entries) {
    if (_tombstones.contains(entry.key)) continue;
    if (_composedDispatch.containsKey(entry.key))
      continue; // already overridden
    if (allowlist != null && !allowlist.contains(entry.key)) continue;
    _dispatch.putIfAbsent(entry.key, () => entry.value);
  }
}