dartToExtern function

Pointer<wasmtime_extern_t> dartToExtern(
  1. Arena arena,
  2. Object value
)

Writes value into a fresh wasmtime_extern_t allocated in arena.

Implementation

ffi.Pointer<c.wasmtime_extern_t> dartToExtern(Arena arena, Object value) {
  final out = arena<c.wasmtime_extern_t>();
  switch (value) {
    case WasmFunc():
      out.ref.kind = WasmExternKind.func.cKind;
      writeFuncHandle(out.ref.of.func, value.handle);
    case WasmMemory():
      out.ref.kind = WasmExternKind.memory.cKind;
      writeMemoryHandle(out.ref.of.memory, value.handle);
    case WasmGlobal():
      out.ref.kind = WasmExternKind.global.cKind;
      writeGlobalHandle(out.ref.of.global, value.handle);
    case WasmTable():
      out.ref.kind = WasmExternKind.table.cKind;
      writeTableHandle(out.ref.of.table, value.handle);
    default:
      throw ArgumentError.value(
        value,
        'value',
        'expected a WasmFunc, WasmMemory, WasmGlobal or WasmTable',
      );
  }
  return out;
}