Skip to content

Commit 4a5f02a

Browse files
Add section on external (#5481)
Fixes #5478 --------- Co-authored-by: Erik Ernst <eernst@google.com>
1 parent b38afe5 commit 4a5f02a

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/language/functions.md

+29
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,28 @@ Iterable<int> naturalsDownFrom(int n) sync* {
500500
}
501501
```
502502

503+
## External functions {#external}
504+
505+
An external function is a function whose body is implemented separately from its
506+
declaration. Include the `external` keyword before a function declaration, like so:
507+
508+
```dart
509+
external void someFunc(int i);
510+
```
511+
512+
An external function's implementation can come from another Dart library,
513+
or, more commonly, from another language. In interop contexts, `external`
514+
introduces type information for foreign functions or values,
515+
making them usable in Dart. Implementation and usage is
516+
heavily platform specific, so check out the interop docs on, for example,
517+
[C][] or [JavaScript][] to learn more.
518+
519+
External functions can be top-level functions, [instance methods][],
520+
[getters or setters][], or [non-redirecting constructors][].
521+
An [instance variable][] can be `external` too,
522+
which is equivalent to an external getter and (if the variable
523+
is not `final`) an external setter.
524+
503525
[`Iterable`]: {{site.dart-api}}/{{site.data.pkg-vers.SDK.channel}}/dart-core/Iterable-class.html
504526
[`Stream`]: {{site.dart-api}}/{{site.data.pkg-vers.SDK.channel}}/dart-async/Stream-class.html
505527
[record]: /language/records#multiple-returns
@@ -511,3 +533,10 @@ Iterable<int> naturalsDownFrom(int n) sync* {
511533
[conditional expression]: /language/operators#conditional-expressions
512534
[Flutter]: {{site.flutter}}
513535
[trailing commas]: /language/collections#lists
536+
537+
[instance methods]: /language/methods#instance-methods
538+
[getters or setters]: /language/methods#getters-and-setters
539+
[non-redirecting constructors]: /language/constructors#redirecting-constructors
540+
[instance variable]: /language/classes#instance-variables
541+
[C]: /interop/c-interop
542+
[JavaScript]: /interop/js-interop

src/language/keywords.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The following table lists the words that the Dart language treats specially.
5858
[export]: /guides/libraries/create-packages
5959
[extends]: /language/extend
6060
[extension]: /language/extension-methods
61-
[external]: https://spec.dart.dev/DartLangSpecDraft.pdf#External%20Functions
61+
[external]: /language/functions#external
6262
[factory]: /language/constructors#factory-constructors
6363
[false]: /language/built-in-types#booleans
6464
[final (variable)]: /language/variables#final-and-const

0 commit comments

Comments
 (0)