-
Notifications
You must be signed in to change notification settings - Fork 4k
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
update: first mapping tutorial revamp #4708
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great addition - I left a couple of comments, please let me know what you think
|
||
Create a `lib.h` file to see how C functions are mapped into Kotlin: | ||
There are the following [data types in the C programming language](https://en.wikipedia.org/wiki/C_data_types): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are the following [data types in the C programming language](https://en.wikipedia.org/wiki/C_data_types): | |
The C programming language has the following [data types](https://en.wikipedia.org/wiki/C_data_types): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might not be the best because of the link anchor with this suggestion, but "There are the following data types" feels a bit awkward to me 🤔
#define LIB2_H_INCLUDED | ||
* Basic types: `char, int, float, double` with modifiers `signed, unsigned, short, long` | ||
* Structures, unions, arrays | ||
* Structures, unions, arrays |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate list element?
|
||
The best way to see what C data types are visible in Kotlin is to try it. | ||
You can use the command line to generate a Kotlin library, either directly or with a script file (such as `.sh` or `.bat` file). | ||
However, this approach doesn't scale well for big projects that have hundreds of files and libraries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, this approach doesn't scale well for big projects that have hundreds of files and libraries. | |
However, this approach doesn't scale well for large projects that have hundreds of files and dependencies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be incorrect to say dependencies instead of libraries but if it's correct I feel like it could be more encompassing than saying libraries here (or perhaps we could say library dependencies?).
with big vs large projects - tbh both works I think large might be a bit more formal but that's it.
You can use the command line to generate a Kotlin library, either directly or with a script file (such as `.sh` or `.bat` file). | ||
However, this approach doesn't scale well for big projects that have hundreds of files and libraries. | ||
Using a build system simplifies the process by downloading and caching the Kotlin/Native | ||
compiler binaries and libraries with transitive dependencies, and by running the compiler and tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compiler binaries and libraries with transitive dependencies, and by running the compiler and tests. | |
compiler binaries and libraries with transitive dependencies, as well as running the compiler and tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be a bit more of a smooth transition but the original is also fine I think
#define LIB2_H_INCLUDED | ||
* Basic types: `char, int, float, double` with modifiers `signed, unsigned, short, long` | ||
* Structures, unions, arrays | ||
* Structures, unions, arrays |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Structures, unions, arrays |
} | ||
``` | ||
The project file configures the C interop as an additional build step. | ||
Check out the [Multiplatform Gradle DSL reference](multiplatform-dsl-reference.md) to learn about all the different |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out the [Multiplatform Gradle DSL reference](multiplatform-dsl-reference.md) to learn about all the different | |
Check out the [Multiplatform Gradle DSL reference](multiplatform-dsl-reference.md) to learn about the different |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(suggestion)
it feels good to me even without it and a bit more concise
|
||
## Primitive types in kotlin | ||
Let's see how C primitive types are mapped into Kotlin/Native and fix the example project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see how C primitive types are mapped into Kotlin/Native and fix the example project. | |
Let's see how C primitive types are mapped into Kotlin/Native and update the example project accordingly. |
With the help of IntelliJ IDEA's __Go to | Declaration__ or | ||
compiler errors, you see the following generated API for the C functions: | ||
With the help of IntelliJ IDEA's [Go to declaration](https://www.jetbrains.com/help/rider/Navigation_and_Search__Go_to_Declaration.html) | ||
command (<shortcut>Cmd + B</shortcut>/<shortcut>Ctrl + B</shortcut>), you can see the following generated API for C functions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
command (<shortcut>Cmd + B</shortcut>/<shortcut>Ctrl + B</shortcut>), you can see the following generated API for C functions: | |
command (<shortcut>Cmd + B</shortcut>/<shortcut>Ctrl + B</shortcut>), you can view the following generated API for C functions: |
|
||
## Update Kotlin code | ||
|
||
Now that you've seen C definitions, you can update Kotlin code. The final code in the `hello.kt` file may look like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that you've seen C definitions, you can update Kotlin code. The final code in the `hello.kt` file may look like this: | |
Now that you've seen the C definitions, you can update the Kotlin code. The final code in the `hello.kt` file may look like this: |
} | ||
``` | ||
|
||
## Next steps | ||
To check that everything works as expected, run the `linkDebugSharedNative` Gradle task [in IDE](native-get-started.md#build-and-run-the-application) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To check that everything works as expected, run the `linkDebugSharedNative` Gradle task [in IDE](native-get-started.md#build-and-run-the-application) | |
To verify that everything works as expected, run the `linkDebugSharedNative` Gradle task [in IDE](native-get-started.md#build-and-run-the-application) |
No description provided.