Skip to content
This repository was archived by the owner on Jan 28, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 6.1.0

- Added `exclude-all-by-default` config flag, which changes the default behavior
of declaration filters to exclude everything, rather than include everything.

# 6.0.2

- Bump `package:ffi` to 2.0.1.
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,21 @@ use-supported-typedefs: true

```yaml
use-dart-handle: true
```
</td>
</tr>
<tr>
<td>exclude-all-by-default</td>
<td>
When a declaration filter (eg `functions:` or `structs:`) is empty or
unset, it defaults to including everything. If this flag is enabled, the
default behavior is to exclude everything instead.<br>
<b>Default: false</b>
</td>
<td>

```yaml
exclude-all-by-default: true
```
</td>
</tr>
Expand Down
80 changes: 44 additions & 36 deletions example/objective_c/README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
# Objective C example
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend you hide whitespace changes for this file. Most of these diffs are just my editor switching the line endings.


This example shows how to use ffigen to generate bindings for an Objective C
library. It uses the AVFAudio framework to play audio files.

```
dart play_audio.dart test.mp3
```

## Config notes

The ffigen config for an Objective C library looks very similar to a C library.
The most important difference is that you must set `language: objc`. If you want
to filter which interfaces are included you can use the `objc-interfaces:`
option. This works similarly to the other filtering options.

It is recommended that you filter out just about everything you're not
interested in binding (see the ffigen config in [pubspec.yaml](./pubspec.yaml)).
Virtually all Objective C libraries depend on Apple's internal libraries, which
are huge. Filtering can reduce the generated bindings from millions of lines to
tens of thousands.

In this example, we're only interested in `AVAudioPlayer`, so we've filtered out
everything else. But ffigen will automatically pull in anything referenced by
any of the fields or methods of `AVAudioPlayer`, so we're still able to use
`NSURL` etc to load our audio file.

## Generating bindings

At the root of this example (`example/objective_c`), run:

```
dart run ffigen
```

This will generate [avf_audio_bindings.dart](./avf_audio_bindings.dart).
# Objective C example

This example shows how to use ffigen to generate bindings for an Objective C
library. It uses the AVFAudio framework to play audio files.

```
dart play_audio.dart test.mp3
```

## Config notes

The ffigen config for an Objective C library looks very similar to a C library.
The most important difference is that you must set `language: objc`. If you want
to filter which interfaces are included you can use the `objc-interfaces:`
option. This works similarly to the other filtering options.

It is recommended that you filter out just about everything you're not
interested in binding (see the ffigen config in [pubspec.yaml](./pubspec.yaml)).
Virtually all Objective C libraries depend on Apple's internal libraries, which
are huge. Filtering can reduce the generated bindings from millions of lines to
tens of thousands. You can use the `exclude-all-by-default` flag, or exclude
individual sets of declarations like this:

```yaml
functions:
exclude:
- '.*'
# Same for structs/unions/enums etc.
```

In this example, we're only interested in `AVAudioPlayer`, so we've filtered out
everything else. But ffigen will automatically pull in anything referenced by
any of the fields or methods of `AVAudioPlayer`, so we're still able to use
`NSURL` etc to load our audio file.

## Generating bindings

At the root of this example (`example/objective_c`), run:

```
dart run ffigen
```

This will generate [avf_audio_bindings.dart](./avf_audio_bindings.dart).
Loading