define method
Defines an exported value under name.
When descriptorOrValue is a DocDescriptor, the descriptor carries both
the documentation metadata and optionally the runtime value:
context.define('echo', FunctionDescriptor(
summary: 'Echoes input.',
params: [DocParam('v', 'any', 'Value.')],
category: 'base',
rawValue: (args) => args.first,
));
context.define('pi', ConstantDescriptor(
summary: 'The value of π.',
type: 'number',
rawValue: 3.1415,
));
context.define('DeviceSide', AliasDescriptor(
name: 'DeviceSide',
variants: [AliasVariant(value: 'left')],
));
When descriptorOrValue is a raw value (e.g. a BuiltinFunction or
Function closure), it is stored directly in the library table. Any
documentation from BuiltinFunction.doc is auto-collected during
initialization.
For registering documentation separately from a value, the describe, describeValue, describeAlias, describeEnum, and describeTable methods are still available.
Implementation
void define(String name, Object? descriptorOrValue) {
if (descriptorOrValue is DocDescriptor) {
_defineWithDescriptor(name, descriptorOrValue);
} else {
_defineRaw(name, descriptorOrValue);
}
}