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(libmecabPath != null) {
    mecabDartFfiHelper = await FfiHelper.load(libmecabPath);
  }
  if(mecabFfiHelper != null) {
    mecabDartFfiHelper = mecabFfiHelper;
  }

  initMecabPointer = mecabDartFfiHelper.library
    .lookup<NativeFunction<InitMecabFunc>>('initMecab');
  initMecabFfi = initMecabPointer.asFunction<InitMecabFunc>();

  parsePointer = mecabDartFfiHelper.library
    .lookup<NativeFunction<ParseFunc>>('parse');
  parseFfi = parsePointer.asFunction<ParseFunc>();

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

  nativeAddFunc = mecabDartFfiHelper.library
    .lookup<NativeFunction<Int32 Function(Int32, Int32)>>('native_add')
    .asFunction();

}