Skip to content

Commit

Permalink
add external section, change keywords link
Browse files Browse the repository at this point in the history
  • Loading branch information
MaryaBelanger committed Jan 23, 2024
1 parent a7f1703 commit 6e9fe76
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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}

Declare a function `external` if its body is defined separately from its
declaration in your Dart program.

```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.

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.



[`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 variables]: /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

0 comments on commit 6e9fe76

Please sign in to comment.