ffi 2.1.3 copy "ffi: ^2.1.3" to clipboard
ffi: ^2.1.3 copied to clipboard

Utilities for working with Foreign Function Interface (FFI) code.

example/main.dart

// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:ffi';

import 'package:ffi/ffi.dart';

void main() {
  // Allocate and free some native memory with calloc and free.
  final pointer = calloc<Uint8>();
  pointer.value = 3;
  print(pointer.value);
  calloc.free(pointer);

  // Use the Utf8 helper to encode zero-terminated UTF-8 strings in native
  // memory.
  final myString = 'πŸ˜ŽπŸ‘ΏπŸ’¬';
  final charPointer = myString.toNativeUtf8();
  print('First byte is: ${charPointer.cast<Uint8>().value}');
  print(charPointer.toDartString());
  calloc.free(charPointer);
}
288
likes
160
pub points
99%
popularity

Publisher

verified publisherdart.dev

Utilities for working with Foreign Function Interface (FFI) code.

Repository (GitHub)
View/report issues
Contributing

Topics

#interop #ffi #codegen

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on ffi