registertopLevelFunction method
void
registertopLevelFunction(
- String? name,
- NativeFunctionImpl function,
- String library, {
- String? sourceUri,
- String? signature,
Registers a top-level native function for use in interpreted code.
name The name by which the function will be accessible in interpreted code.
function The native function implementation to be called.
library The library path (package URI) where this function is exported from.
The function is only added to the environment when this library is imported.
sourceUri The canonical source URI where this function is defined.
Used for deduplication when the same function is exported through multiple barrels.
signature The full signature of the function as a display string.
Implementation
void registertopLevelFunction(
String? name,
NativeFunctionImpl function,
String library, {
String? sourceUri,
String? signature,
}) {
final nativeFunc = NativeFunction(function, name: name, arity: 0);
final libFunc = LibraryFunction(
nativeFunc,
sourceUri: sourceUri,
signature: signature,
);
_libraryFunctions.add({library: libFunc});
_runner.registerTopLevelFunction(
name,
function,
library,
sourceUri: sourceUri,
signature: signature,
);
_bridgedLibraryUris.add(library);
}