wasm_ffi 2.0.5 copy "wasm_ffi: ^2.0.5" to clipboard
wasm_ffi: ^2.0.5 copied to clipboard

A wrapper for wasm which can be used as a drop-in replacement for dart:ffi for Web platform.

example/lib/example.dart

library example;

import 'package:wasm_ffi/ffi.dart';
import 'package:wasm_ffi/ffi_utils.dart';
import 'native_example_bindings.dart';

class Example {
  final DynamicLibrary library;
  final NativeExampleBindings bindings;

  Example._(this.library) : bindings = NativeExampleBindings(library);

  static Future<Example> create(String libPath) async {
    final library = await DynamicLibrary.open(libPath);
    return Example._(library);
  }

  String getLibraryName() =>
      bindings.getLibraryName().cast<Utf8>().toDartString();

  String hello(String name) {
    return using(
      (Arena arena) {
        final cString = name.toNativeUtf8(allocator: arena).cast<Char>();
        return bindings.hello(cString).cast<Utf8>().toDartString();
      },
      library.allocator,
    );
  }

  int intSize() => bindings.intSize();

  int boolSize() => bindings.boolSize();

  int pointerSize() => bindings.pointerSize();
}
10
likes
0
points
612
downloads

Publisher

verified publishervm75.duckdns.org

Weekly Downloads

A wrapper for wasm which can be used as a drop-in replacement for dart:ffi for Web platform.

Repository (GitHub)
View/report issues

Topics

#ffi #wasm #native #web

License

unknown (license)

Dependencies

ffi, http, meta, path, web

More

Packages that depend on wasm_ffi