StdModuleHandler class

The built-in std module handler.

Provides the universal std library functions. Can be customised before passing to BallEngine:

// Register a custom function alongside the built-ins:
final std = StdModuleHandler()
  ..register('my_func', (input) => 42);

// Override the default print implementation:
final std = StdModuleHandler()
  ..register('print', (i) { myLogger.log(i); return null; });

// Only expose a subset of functions (e.g. no math, no collections):
final std = StdModuleHandler.subset({'print', 'add', 'subtract', 'equals'});

final engine = BallEngine(program, moduleHandlers: [std]);
Inheritance

Constructors

StdModuleHandler()
Creates a handler that exposes the full set of built-in std functions.
StdModuleHandler.subset(Iterable<String> functions)
Creates a handler that only exposes the named functions.

Properties

hashCode int
The hash code for this object.
no setterinherited
registeredFunctions Set<String>
All function names currently registered in this handler.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

call(String function, Object? input, BallCallable engine) FutureOr<Object?>
Executes function with the given input value.
override
handles(String module) bool
Returns true when this handler is responsible for module.
override
init(BallEngine engine) → void
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.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
register(String function, FutureOr<Object?> handler(Object?)) → void
Register or override the handler for function (engine-unaware closure).
registerComposer(String function, FutureOr<Object?> handler(Object?, BallCallable )) → void
Register or override a composition-aware handler for function.
toString() String
A string representation of this object.
inherited
unregister(String function) → void
Remove function from this handler.

Operators

operator ==(Object other) bool
The equality operator.
inherited