Got a question about " ```kotlinx.cinterop.staticC...
# kotlin-native
j
Got a question about "
Copy code
kotlinx.cinterop.staticCFunction
" when called as a callback from C . (Thread/SO link)
s
As far as I know, you can't. Which sucks.
n
There are some workarounds depending on the situation. For example a Kotlin class that takes a
CPointer
(in the primary constructor) can be instantiated in the event handler, which is handy when the state/functionality is being passed through to the event handler as a
CPointer
. The class instance uses that
CPointer
to access the state/functionality.
k
You can pass Kotlin Function to C method by declare it outside class or object For example :
fun example(inputPointer: COpaquePointer?) { println(inputPointer.reinterpret<String>()) } // Globally
//Then pass it like.
anyCMethod(staticCFunction(::example).reinterpret(), "hello".cstr/* input parameter for your function*/)
I explained it in simple way.