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 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
29 changes: 29 additions & 0 deletions src/language/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,28 @@ Iterable<int> naturalsDownFrom(int n) sync* {
}
```

## External functions {#external}

An external function is a function whose body is implemented separately from its
declaration. Include the `external` keyword before a function declaration, like so:

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

An external function's implementation can come from another Dart library,
or, more commonly, from another language. In interop contexts, `external`
introduces type information for foreign functions or values,
making 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

External functions can be top-level functions, [instance methods][],
[getters or setters][], or [non-redirecting constructors][].
An [instance variable][] can be `external` too,
which is equivalent to an external getter and (if the variable
is not `final`) an external setter.

[`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 +533,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 variable]: /language/classes#instance-variables
[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
Loading