ffi_tool 0.1.0 ffi_tool: ^0.1.0 copied to clipboard
Generates 'dart:ffi' bindings for C and Objective-C libraries.
Overview #
This library helps developers to generate dart:ffi bindings.
When you generate bindings for an iOS / Mac OS X library that uses the reference counting, the generated bindings will use cupertino_ffi.
Contributing #
- Create a pull request in github.com/dart-interop/ffi_tool.
- You can also get Github push/admin permits by creating an issue.
Getting started #
Add dependency #
In "pubspec.yaml":
dev_dependencies:
ffi_tool: ^0.1.0
Run pub get
.
Write a script #
Create a generator script in some file (example: "tool/generate_ffi.dart"):
import 'package:ffi_tool/c.dart';
import 'dart:io';
void main() {
generateFile(File("lib/src/generated.dart"), library);
}
final library = Library(
dynamicLibraryIdentifier: "dlForExampleLibrary",
dynamicLibraryPath: "path/to/library",
importedUris: [
"package:ffi/ffi.dart",
],
elements: <Element>[
// C function
Func(
name: "Example",
parameterTypes: ["Int32", "Floa64", "*void", "void"],
returnType: "ReturnType",
),
// C global variable
Global(
name: "ExampleGlobal",
type: "Int32",
),
],
);
Run it #
pub run tool/generate_ffi.dart