initTypes function

void initTypes([
  1. int pointerSizeBytes = 4
])

Must be called before working with wasm_ffi to initalize all type sizes.

The optional parameter pointerSizeBytes can be used to adjust the size of pointers. It defaults to 4 since WebAssembly usually uses 32 bit pointers. If you want to use wasm64, set pointerSizeBytes to 8 to denote 64 bit pointers.

Implementation

void initTypes([int pointerSizeBytes = 4]) {
  if (registeredPointerSizeBytes != null) {
    if (registeredPointerSizeBytes != pointerSizeBytes) {
      throw MarshallingException(
          'Can not change pointer size after it was set to $registeredPointerSizeBytes!');
    }
    return;
  }
  registeredPointerSizeBytes = pointerSizeBytes;
  _registerType<Int>(pointerSizeBytes);
  _registerType<UnsignedInt>(pointerSizeBytes);
  _registerType<Float>(4);
  _registerType<Double>(8);
  _registerType<Int8>(1);
  _registerType<Uint8>(1);
  _registerType<Int16>(2);
  _registerType<Uint16>(2);
  _registerType<Int32>(4);
  _registerType<Uint32>(4);
  _registerType<Int64>(8);
  _registerType<Uint64>(8);
  _registerType<Size>(pointerSizeBytes);
  _registerType<IntPtr>(pointerSizeBytes);
  _registerType<UintPtr>(pointerSizeBytes);
  _registerType<Opaque>(pointerSizeBytes);
  _registerNativeMarshallerType<Void>();
  _registerNativeMarshallerType<NativeFunction<dynamic>>();
}