init method

Future<void> init({
  1. String? libmecabPath,
  2. FfiHelper? mecabFfiHelper,
})

Initializes the communication to ffi

Implementation

Future<void> init({String? libmecabPath, FfiHelper? mecabFfiHelper}) async {

  if (libmecabPath == null && mecabFfiHelper == null) {
    throw ArgumentError("Not **both** `libmecabPath` and `mecabFfiHelper` can be null!");
  }

  if (mecabFfiHelper != null) {
    mecabDartFfiHelper = mecabFfiHelper;
  }
  else if (libmecabPath != null) {
    mecabDartFfiHelper = await FfiHelper.load(libmecabPath);
  }

  // Lookup functions
  initMecabFfi = mecabDartFfiHelper.library
    .lookup<NativeFunction<InitMecabFuncC>>('initMecab')
    .asFunction<InitMecabFuncDart>();

  destroyMecabFfi = mecabDartFfiHelper.library
    .lookup<NativeFunction<DestroyMecabFuncC>>('destroyMecab')
    .asFunction<DestroyMecabFuncDart>();

  parseFfi = mecabDartFfiHelper.library
    .lookup<NativeFunction<ParseFuncC>>('parse')
    .asFunction<ParseFuncDart>();

  nativeAddFunc = mecabDartFfiHelper.library
    .lookup<NativeFunction<NativeAddFuncC>>('native_add')
    .asFunction<NativeAddFuncDart>();
}