WasmTable.create constructor

WasmTable.create(
  1. WasmStore store,
  2. WasmValueKind element, {
  3. required int initial,
  4. int? maximum,
  5. Object? fill,
})

Creates a new table in store.

Implementation

factory WasmTable.create(
  WasmStore store,
  WasmValueKind element, {
  required int initial,
  int? maximum,
  Object? fill,
}) => scoped((arena) {
  final limits = arena<c.wasm_limits_t>()
    ..ref.min = initial
    ..ref.max = maximum ?? c.wasm_limits_max_default;
  // `wasm_tabletype_new` takes ownership of the element type.
  final tableType = c.wasm_tabletype_new(
    c.wasm_valtype_new(element.wasmKind),
    limits,
  );
  try {
    final init = arena<c.wasmtime_val_t>();
    writeValue(init, element, fill);
    final out = arena<c.wasmtime_table_t>();
    throwIfError(c.wasmtime_table_new(store.context, tableType, init, out));
    return WasmTable._(store, readTableHandle(out.ref));
  } finally {
    c.wasm_tabletype_delete(tableType);
  }
});