load static method
Loads a dynamic library from the specified modulePath
and returns
an FfiHelper instance encapsulating the library.
Given modulePath
as <path>/<name>
, depending on the platform, it looks for
<name>.wasm
, <name>.js
, lib<name>.so
, <name>.dll
, lib<name>.dylib
in the same relative folder <path>
.
If <name>.wasm
is used, it assumes Standalone wasm for web and
lib<name>.so
, <name>.dll
, lib<name>.dylib
for other platforms.
If <name>.js
is used, it assumes Emscripten wasm for web and
lib<name>.so
, <name>.dll
, lib<name>.dylib
for other platforms.
modulePath
: The path to the module to be loaded.
options
: Optional load options, all defaulting to false.
- isStaticallyLinked: non-web modules are statically linked.
- isFfiPlugin: this is a Ffi plugin.
- isStandaloneWasm: indicates whether the wasm is standalone.
overrides
: AppType specific overrides to the path to the module to be loaded. - Empty override indicates that the module is statically linked.
Returns a Future that completes with an FfiHelper instance. Throws an ArgumentError if the module cannot be found.
Implementation
static Future<FfiHelper> load(
String modulePath, {
Set<LoadOption> options = const {},
Map<AppType, String> overrides = const {},
}) async {
modulePath = overrides[appType] ?? resolveModulePath(modulePath, options);
// If module path is empty, it is treated as a statically linked library
// This is not supported for Web/Wasm
if (modulePath.isEmpty || options.contains(LoadOption.isStaticallyLinked)) {
if (appType == AppType.web) {
throw ArgumentError(
'Statically linked library is not supported for Web/Wasm',
);
}
return FfiHelper._(DynamicLibrary.process());
}
return FfiHelper._(
await DynamicLibrary.open(modulePath),
);
}