Also how can I pass a function as a parameter via ...
# kotlin-native
p
Also how can I pass a function as a parameter via C?
a
p
No, I want to pass a C function as a parameter to a Kotlin function. If I have a Kotlin function that looks like this:
fun test(param1: () -> Unit) {...}
how would I create a C function and pass it as a parameter? I am talking about exporting my project as a dynamic library
a
Please have a look at this, I hope that I understood you correctly:
Copy code
Kotlin code:
fun execCFunction(cFunc: CFunction<() -> Unit>){
    cFunc.ptr.invoke()
}

C code:
void printThings() {
    printf("IM INVOKED FROM KOTLIN !\n");
}
int main() {
    dynamic_ExportedSymbols* lib = dynamic_symbols();
    lib->kotlin.root.sample.execCFunction(&printThings);
    return 0;
}
p
Yes, exactly!
🎉 1
Is that how I can do it, or just for clarification?
a
Yep, this one worked for me, so give it a try.
👍 1
p
This works, thank you so much 🙂