Didier Villevalois
01/01/2026, 11:43 AM@Suppress("errors") but that doesn't work. I understand the risks, and let just say that "I know what I am doing" (hm hm...).
package kextract.runtime
import kotlinx.cinterop.ExperimentalForeignApi
@OptIn(ExperimentalForeignApi::class)
@Suppress("errors")
actual fun <R> staticCFunction(function: () -> Unit): CPointer<() -> R> {
return CPointer.Opaque(kotlinx.cinterop.staticCFunction(function).rawValue.toLong().toMemorySize())
// ^^^^^ kotlinx.cinterop.staticCFunction must take an unbound, non-capturing function or lambda
}
Any hints as to how I should proceed? (Ideally, I would like that the Kotlin compiler applies the same check to users of my custom staticCFunction but I guess that's another question for another day.)Youssef Shoaib [MOD]
01/01/2026, 12:40 PMDidier Villevalois
01/01/2026, 12:48 PMAdam S
01/01/2026, 12:49 PMAdam S
01/01/2026, 12:51 PMYoussef Shoaib [MOD]
01/01/2026, 12:52 PMYoussef Shoaib [MOD]
01/01/2026, 12:54 PMexternal implementation. You'd then be able to get what you want without any of the static checks. It seems like it's an intrinsic that the compiler deals with, though...Didier Villevalois
01/01/2026, 12:58 PMDidier Villevalois
01/01/2026, 1:00 PM@CCall for my generated bindings, thanks to Oleg and his kotlin-interop-playground !)Didier Villevalois
01/01/2026, 1:03 PMcinterop would be more open and documented. 😊 (Or have multiplatform cinterop... 😁)Adam S
01/01/2026, 1:07 PMI understand the non-capturing aspect and it's not a problemcould you say more? (I'm asking because I'd like to learn more about the C side of K/N development)
Adam S
01/01/2026, 1:08 PMDidier Villevalois
01/01/2026, 1:10 PMcinterop. I generate bindings that directly bind to C via external functions. (And it's a bit of a mess! 😊)
I recommend you to look at Oleg's Kotlin Interop Playground . It will give you a good overview of the ways to bind to C. He does it two ways: with cinterop in c-interop/native-cinterop and without, in c-inherop/native-raw.Adam S
01/01/2026, 1:16 PMstaticCFunction.loke
01/01/2026, 3:57 PMDidier Villevalois
01/01/2026, 4:44 PMtoNativeFunctionPointer) that takes a Kotlin function (let's call it f) and returns a native function pointer. That native function pointer would convert parameters from Kotlin to native, then calls f, and finally converts the return value from native to Kotlin. The conversions are easy and done. The hard part is the "calling the Kotlin function".