https://kotlinlang.org logo
Title
b

brandonlamb

06/19/2018, 3:50 PM
Hello all. I have a question that Google has not been able to help me with. Does K/N currently support C -> Kotlin interop? If so, any documentation? If not, is this a planned/roadmap feature? I'm trying to integrate Kotlin Native with the Godot game engine, I have a dynlib compiling but I'm realizing I dont know how to expose a
godot_gdnative_init()
function for the game engine to find and call.
or maybe you mean the other way around?
b

brandonlamb

06/19/2018, 4:03 PM
https://blog.jetbrains.com/kotlin/2017/12/kotlinnative-v0-5-released-calling-kotlin-from-swift-and-c-llvm-5-and-more/ Just came across this, looks like it is supported but I'm not seeing docs/examples yet. Yes I mean the other way around, C calling into a Kotlin Native code/library
https://github.com/godot-addons/godot-kotlin So far I have code that does the cinterop against the C API for godot engine, and trying to expose the two functions that godot needs
godot_gdnative_init()
and
godot_gdnative_terminate()
. I get a dynlib compiled, and when I try to load this, godot says it cant find the function. I'm assuming that I'm missing a step, or annotation, or something
d

dany

06/19/2018, 4:15 PM
s

svyatoslav.scherbina

06/19/2018, 4:43 PM
We have a sample for this feature with dynamic libs: https://github.com/JetBrains/kotlin-native/tree/master/samples/python_extension To expose a function under predictable name you can use
@konan.internal.CName
annotation:
@konan.internal.CName("godot_gdnative_init")
fun godot_gdnative_init(o: CPointer<godot_gdnative_init_options>>?) {
}
(or something like this).
Also if you only need to expose a couple of functions, you have an option to compile to program instead of dynamic library, but expose the function with
@konan.internal.ExportForCppRuntime
. However this annotation is more internal 🙂