Skip to content

Commit e768a80

Browse files
authored
update: final tutorial revamp (#4748)
1 parent 625336b commit e768a80

File tree

4 files changed

+155
-250
lines changed

4 files changed

+155
-250
lines changed

docs/topics/native/mapping-function-pointers-from-c.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
[//]: # (title: Mapping function pointers from C – tutorial)
22

33
<tldr>
4-
<p>This is the third part of the <strong>Mapping Kotlin and C</strong> tutorial series.</p>
4+
<p>This is the third part of the <strong>Mapping Kotlin and C</strong> tutorial series. Before proceeding, make sure you've completed the previous steps.</p>
55
<p><img src="icon-1-done.svg" width="20" alt="First step"/> <a href="mapping-primitive-data-types-from-c.md">Mapping primitive data types from C</a><br/>
66
<img src="icon-2-done.svg" width="20" alt="Second step"/> <a href="mapping-struct-union-types-from-c.md">Mapping struct and union types from C</a><br/>
77
<img src="icon-3.svg" width="20" alt="Third step"/> <strong>Mapping function pointers</strong><br/>
88
<img src="icon-4-todo.svg" width="20" alt="Fourth step"/> <a href="mapping-strings-from-c.md">Mapping strings from C</a><br/>
99
</p>
1010
</tldr>
1111

12-
> The C libraries import is [Experimental](components-stability.md#stability-levels-explained).
13-
> All Kotlin declarations generated by the `cinterop` tool from C libraries
14-
> should have the `@ExperimentalForeignApi` annotation.
12+
> The C libraries import is [Experimental](components-stability.md#stability-levels-explained). All Kotlin declarations
13+
> generated by the cinterop tool from C libraries should have the `@ExperimentalForeignApi` annotation.
1514
>
1615
> Native platform libraries shipped with Kotlin/Native (like Foundation, UIKit, and POSIX)
1716
> require opt-in only for some APIs.
@@ -75,7 +74,7 @@ Let's see how C function pointers are mapped into Kotlin/Native and update your
7574
}
7675
```
7776

78-
2. Use the IntelliJ IDEA's [Go to declaration](https://www.jetbrains.com/help/rider/Navigation_and_Search__Go_to_Declaration.html)
77+
2. Use IntelliJ IDEA's [Go to declaration](https://www.jetbrains.com/help/rider/Navigation_and_Search__Go_to_Declaration.html)
7978
command (<shortcut>Cmd + B</shortcut>/<shortcut>Ctrl + B</shortcut>) to navigate to the following generated API
8079
for C functions:
8180

@@ -134,7 +133,7 @@ fun myFun2() {
134133

135134
Kotlin turns the function pointer return type into a nullable `CPointer<CFunction<>` object. You need to first explicitly
136135
check for `null`, which is why the [Elvis operator](null-safety.md) is used in the code above.
137-
The `cinterop` tool allows you to call a C function pointer as a regular Kotlin function call: `functionFromC(42)`.
136+
The cinterop tool allows you to call a C function pointer as a regular Kotlin function call: `functionFromC(42)`.
138137

139138
## Update Kotlin code
140139

@@ -159,7 +158,7 @@ fun main() {
159158
}
160159
```
161160

162-
To verify that everything works as expected, run the `runDebugExecutableNative` Gradle task [in IDE](native-get-started.md#build-and-run-the-application)
161+
To verify that everything works as expected, run the `runDebugExecutableNative` Gradle task [in your IDE](native-get-started.md#build-and-run-the-application)
163162
or use the following command to run the code:
164163

165164
```bash

docs/topics/native/mapping-primitive-data-types-from-c.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
</p>
1010
</tldr>
1111

12-
> The C libraries import is [Experimental](components-stability.md#stability-levels-explained).
13-
> All Kotlin declarations generated by the `cinterop` tool from C libraries
14-
> should have the `@ExperimentalForeignApi` annotation.
12+
> The C libraries import is [Experimental](components-stability.md#stability-levels-explained). All Kotlin declarations
13+
> generated by the cinterop tool from C libraries should have the `@ExperimentalForeignApi` annotation.
1514
>
1615
> Native platform libraries shipped with Kotlin/Native (like Foundation, UIKit, and POSIX)
1716
> require opt-in only for some APIs.
@@ -89,7 +88,7 @@ To create a C library:
8988
headers = lib.h
9089
```
9190

92-
4. It can be helpful to include macros or other C definitions in the code generated by the `cinterop` tool. This way,
91+
4. It can be helpful to include macros or other C definitions in the code generated by the cinterop tool. This way,
9392
method bodies are also compiled and fully included in the binary. With this feature, you can create a runnable example
9493
without needing a C compiler.
9594

@@ -220,7 +219,7 @@ You'll complete the code later as you learn how C primitive type declarations lo
220219
221220
Let's see how C primitive types are mapped into Kotlin/Native and update the example project accordingly.
222221
223-
Use the IntelliJ IDEA's [Go to declaration](https://www.jetbrains.com/help/rider/Navigation_and_Search__Go_to_Declaration.html)
222+
Use IntelliJ IDEA's [Go to declaration](https://www.jetbrains.com/help/rider/Navigation_and_Search__Go_to_Declaration.html)
224223
command (<shortcut>Cmd + B</shortcut>/<shortcut>Ctrl + B</shortcut>) to navigate to the following generated API
225224
for C functions:
226225

0 commit comments

Comments
 (0)