Description
Our current syntax for "ffi-natives" is still a bit verbose.
@FfiNative<Int64 Function(Int64, Int64)>('sum')
external int sum(int a, int b);
1. Rename FfiNative
to Native
We could consider @Ffi<...>
and @Native<...>
.
sum
is an external function.
sum
is a native function.
sum
is not an "ffi" function, the mechanism for calling sum
is "ffi".
This makes it most natural to change the syntax to:
@Native<Int64 Function(Int64, Int64)>('sum')
external int sum(int a, int b);
Courtesy of @mit-mit and @mkustermann.
2. Make the symbol optional
If the symbol in C is identical to the Dart symbol, we don't need to repeat it.
@Native<Int64 Function(Int64, Int64)>()
external int sum(int a, int b);
Wish list. Don't write dart types
The native types uniquely define the Dart types, so it would be nice if we could omit the Dart types
@Native()
external Int64 sum(Int64 a, Int64 b);
@Native()
external Void foo(Pointer<Int64> a, Int64 b);
However, we would need some kind of transformation before any Dart static analysis runs to replace the native types with the corresponding Dart code. Otherwise, calling a function with Dart integers will not pass type checks.
We would likely need macros for this, if our approach for macros could already support this.
Misc
The old natives are deprecated, so we don't have to worry about naming collision (having to designate the new natives as "new native" or "ffi native"). FWIW the syntax of the deprecated old natives:
@pragma("vm:external-name", "File_OpenStdio")
external static int _openStdio(int fd);
See d8d7af1.