universal_ffi 1.1.1 copy "universal_ffi: ^1.1.1" to clipboard
universal_ffi: ^1.1.1 copied to clipboard

A drop-in replacement for dart:ffi for all platforms including web (using wasm_ffi).

example/lib/example.dart

import 'package:universal_ffi/ffi.dart';
import 'package:universal_ffi/ffi_helper.dart';
import 'package:universal_ffi/ffi_utils.dart';
import 'native_example_bindings.dart';

class Example {
  final FfiHelper helper;
  final NativeExampleBindings bindings;

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

  static Future<Example> create(String libPath) async {
    final helper = await FfiHelper.load(libPath);
    return Example._(helper);
  }

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

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

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

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

  int pointerSize() => bindings.pointerSize();
}
4
likes
0
points
324
downloads

Publisher

verified publishervm75.duckdns.org

Weekly Downloads

A drop-in replacement for dart:ffi for all platforms including web (using wasm_ffi).

Repository (GitHub)
View/report issues

Topics

#ffi #wasm #native #web #cross-platform

License

unknown (license)

Dependencies

ffi, path, wasm_ffi

More

Packages that depend on universal_ffi