BallModuleHandler class abstract
Contract for a ball base-module handler.
BallEngine routes every isBase function call through its registered
moduleHandlers, delegating to the first one whose handles returns
true. Implement this class to add entirely new modules or to replace
the built-in StdModuleHandler:
class DbHandler extends BallModuleHandler {
@override bool handles(String module) => module == 'db';
@override Object? call(String fn, Object? input, BallCallable engine) {
return switch (fn) {
'query' => _runQuery(input),
_ => throw BallRuntimeError('Unknown db function: "$fn"'),
};
}
}
Composition-only ball modules
If a ball program module contains only user-defined (non-isBase)
functions that delegate to other modules, no handler is needed at all.
The engine evaluates their bodies and resolves cross-module calls
automatically:
// ball program (proto/JSON)
module math_utils:
function hypotenuse(a, b): // isBase: false, has a body
std.math_sqrt(std.add(std.math_pow(a,2), std.math_pow(b,2)))
Handler composition (handler calling handler)
If your handler needs to call another ball function (user-defined or from another module), use the BallCallable passed to call:
class MathFacade extends BallModuleHandler {
@override bool handles(String m) => m == 'myfacade';
@override Object? call(String fn, Object? input, BallCallable engine) {
if (fn == 'taxed_total')
return engine('myfacade', 'subtotal', input)
+ engine('tax', 'compute', input);
throw BallRuntimeError('unknown: $fn');
}
}
- Implementers
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
call(
String function, Object? input, BallCallable engine) → FutureOr< Object?> -
Executes
functionwith the giveninputvalue. -
handles(
String module) → bool -
Returns true when this handler is responsible for
module. -
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.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited