FfiGenerator class final Apple APIs Objective-C Memory Management Objective-C Method Filtering Dealing with OS Differences Objective-C Runtime Types Objective-C Threading Errors FAQ

The generator that generates bindings for dart:ffi from C and Objective-C headers.

At a minimum, you must specify the inputs, the outputs, and which APIs you want to generate bindings for (using visitors).

Example

import 'package:ffigen/ffigen.dart';

Future<void> main() async {
  final generator = FfiGenerator(
    output: Output(
      dart: DartOutput(path: Uri.file('lib/bindings.dart')),
    ),
    input: Input(
      entryPoints: [Uri.file('src/my_c_header.h')],
    ),
    visitors: [
      Visitor(
        func: (node) => node.isIncluded = true,
      ),
    ],
  );
  await generator.generate();
}

Constructors

FfiGenerator({Input input = const Input(), Cpp? cpp, ObjectiveC? objectiveC, required Output output, List<Visitor> visitors = const [], ImportedType? importType(Declaration declaration) = _defaultImportType, @Deprecated('Only visible for YamlConfig plumbing.') Uri? libclangDylib})
const

Properties

cpp Cpp?
C++ specific configuration.
final
hashCode int
The hash code for this object.
no setterinherited
importType ImportedType? Function(Declaration declaration)
Returns an ImportedType if the given Declaration should be imported from another Dart library, or null otherwise.
final
input Input
The configuration for header parsing of FfiGenerator.
final
libclangDylib Uri?
Path to the clang library.
final
objectiveC ObjectiveC?
Objective-C specific configuration.
final
output Output
The configuration for outputting bindings.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
visitors List<Visitor>
AST visitors to run on the generated bindings to perform transformations before Dart code generation occurs.
final

Methods

generate({Logger? logger, Uri? libclangDylib}) Future<void>
Run this generator.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited