Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add section on external #5481

Merged
merged 8 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
26 changes: 26 additions & 0 deletions src/language/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,25 @@ Iterable<int> naturalsDownFrom(int n) sync* {
}
```

## External functions {#external}

An external function is a function whose body is provided separately from its declaration.
parlough marked this conversation as resolved.
Show resolved Hide resolved

```dart
external void someFunc(int i);
```

External functions can be top-level functions, [instance methods][],
[getters or setters][], or [non-redirecting constructors][].
[Instance variables][] can be `external` too,
and essentially equate to a getter or setter on the external value.
MaryaBelanger marked this conversation as resolved.
Show resolved Hide resolved

The `external` keyword usually appears in interop contexts,
to introduce type information for foreign functions or values,
and to make them usable in Dart. Implementation and usage is
heavily platform specific, so check out the interop docs on, for example,
[C][] or [JavaScript][] to learn more.
parlough marked this conversation as resolved.
Show resolved Hide resolved

[`Iterable`]: {{site.dart-api}}/{{site.data.pkg-vers.SDK.channel}}/dart-core/Iterable-class.html
[`Stream`]: {{site.dart-api}}/{{site.data.pkg-vers.SDK.channel}}/dart-async/Stream-class.html
[record]: /language/records#multiple-returns
Expand All @@ -511,3 +530,10 @@ Iterable<int> naturalsDownFrom(int n) sync* {
[conditional expression]: /language/operators#conditional-expressions
[Flutter]: {{site.flutter}}
[trailing commas]: /language/collections#lists

[instance methods]: /language/methods#instance-methods
[getters or setters]: /language/methods#getters-and-setters
[non-redirecting constructors]: /language/constructors#redirecting-constructors
[Instance variables]: /language/classes#instance-variables
MaryaBelanger marked this conversation as resolved.
Show resolved Hide resolved
[C]: /interop/c-interop
[JavaScript]: /interop/js-interop
2 changes: 1 addition & 1 deletion src/language/keywords.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The following table lists the words that the Dart language treats specially.
[export]: /guides/libraries/create-packages
[extends]: /language/extend
[extension]: /language/extension-methods
[external]: https://spec.dart.dev/DartLangSpecDraft.pdf#External%20Functions
[external]: /language/functions#external
[factory]: /language/constructors#factory-constructors
[false]: /language/built-in-types#booleans
[final (variable)]: /language/variables#final-and-const
Expand Down