dart-lang / dart-lang/native

Option to generate pointers to fields on struct pointers

Open
#331 0 comments 2 reactions 0 assignees View on GitHub
package:ffigen type-enhancement waiting-on-dart-ffi
Dominant language
Dart
Stars
275
Forks
144
Avg merge
2d 10h
Merged PRs (30d)
47

Description

After we address https://github.com/dart-lang/sdk/issues/41237.

We can add an option to generate extension methods for `Pointer`s to fields of `Pointer`:

If we settle on an API like this for getting the offsets:

```dart
class MyStruct extends Struct {
@Int32()
external int foo;
@Int64()
external int bar;

@OffsetOf(#foo)
external const int offsetOfFoo;
@OffsetOf(#bar)
external const int offsetOfBar;
}
```

Then we could generate extension methods such as:

```dart
extension MyStructFields on Pointer {
Pointer foo => Pointer.fromAddress(address + MyStruct.offsetOfFoo);

Pointer bar => Pointer.fromAddress(address + MyStruct.offsetOfBar);
}
```

Which would be handy for cases like https://github.com/dart-lang/ffi/issues/117.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.