You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/topics/native/mapping-strings-from-c.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,8 +154,8 @@ fun passStringToC() {
154
154
}
155
155
```
156
156
157
-
Here, the `.toKString()` extension function converts a C string returned from the `return_string()` function
158
-
into a Kotlin string.
157
+
Here, the [`.toKString()`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlinx.cinterop/to-k-string.html) extension
158
+
function converts a C string returned from the `return_string()` function into a Kotlin string.
159
159
160
160
Kotlin provides several extension functions for converting C `char *` strings into Kotlin strings,
161
161
depending on the encoding:
@@ -195,9 +195,9 @@ fun sendString() {
195
195
}
196
196
```
197
197
198
-
Here, a native pointer is passed to the C function first. The `.usePinned` extension function temporarily
199
-
pins the native memory address of the byte array. The C function fills in the byte array with data. Another extension
200
-
function, `ByteArray.decodeToString()`, turns the byte array into a Kotlin string, assuming UTF-8 encoding.
198
+
Here, a native pointer is passed to the C function first. The [`.usePinned()`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlinx.cinterop/use-pinned.html)
199
+
extension function temporarily pins the native memory address of the byte array. The C function fills in the byte array with data.
200
+
Another extension function, `ByteArray.decodeToString()`, turns the byte array into a Kotlin string, assuming UTF-8 encoding.
Copy file name to clipboardExpand all lines: docs/topics/native/native-c-interop.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@
12
12
This document covers general aspects of Kotlin's interoperability with C. Kotlin/Native comes with a cinterop tool,
13
13
which you can use to quickly generate everything you need to interact with an external C library.
14
14
15
-
The tool analyzes C headers and produces a straightforward mapping of C types, functions, and constants into Kotlin.
15
+
The tool analyzes C headers and produces a straightforward mapping of C types, functions, and strings into Kotlin.
16
16
The generated stubs then can be imported into an IDE to enable code completion and navigation.
17
17
18
18
> Kotlin also provides interoperability with Objective-C. Objective-C libraries are imported through the cinterop tool
@@ -401,7 +401,7 @@ and pointers to such objects' inner data could be passed to C functions.
401
401
402
402
There's a couple of approaches you can take:
403
403
404
-
* Use the [`usePinned`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlinx.cinterop/use-pinned.html)service function
404
+
* Use the [`.usePinned()`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlinx.cinterop/use-pinned.html)extension function
405
405
that pins an object, executes a block, and unpins it on normal and exception paths:
406
406
407
407
```kotlin
@@ -423,10 +423,10 @@ There's a couple of approaches you can take:
423
423
}
424
424
```
425
425
426
-
Here, `pinned` is an object of a special type `Pinned<T>`. It provides useful extensions like `addressOf`, which allows
427
-
getting the address of a pinned array body.
426
+
Here, `pinned` is an object of a special type `Pinned<T>`. It provides useful extensions like [`.addressOf()`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlinx.cinterop/address-of.html),
427
+
which allows getting the address of a pinned array body.
428
428
429
-
* Use the [`refTo()`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlinx.cinterop/ref-to.html) function that has
429
+
* Use the [`.refTo()`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlinx.cinterop/ref-to.html) extension function that has
430
430
similar functionality under the hood but, in certain cases, may help you reduce boilerplate code:
431
431
432
432
```kotlin
@@ -498,9 +498,9 @@ fun test() {
498
498
499
499
## What's next
500
500
501
-
Learn how types, functions, and constants are mapped between Kotlin and C by completing the following tutorials:
501
+
Learn how types, functions, and strings are mapped between Kotlin and C by completing the following tutorials:
502
502
503
503
*[Mapping primitive data types from C](mapping-primitive-data-types-from-c.md)
504
-
*[Mapping struct and union types from C](mapping-function-pointers-from-c.md)
504
+
*[Mapping struct and union types from C](mapping-struct-union-types-from-c.md)
505
505
*[Mapping function pointers from C](mapping-function-pointers-from-c.md)
506
506
*[Mapping strings from C](mapping-strings-from-c.md)
0 commit comments