Hi. Can anybody give link to simple example of usi...
# kotlin-native
r
Hi. Can anybody give link to simple example of using C struct in Kotlin Native code? For example, I have
someHeader.h
Copy code
struct my_strucs{
    uint32_t id;
   char * name;
}
What can I do for using it in Kotlin code?
o
Put struct declaration to the .def file after
—-
separator, or refer someHeader in
headers
section of the .def file, and then run cinterop tool on such def file. Please read INTEROP.md.
r
It's described in docs, but how to use this struct inside .kt? I already understood that it is converted into a class. In my case like
Copy code
package someHeader
class my_struct(rawPtr : NativePtr) : ...
But I can't find any docs about creating
NativePtr
o
How do you want to use it? If some C function takes
my_strucs*
parameter then bridge will automatically produce structure class out of the pointer. And generally, calling C function or calling
alloc
is pretty much the only way to get C structure.
r
I try to study interop between KN and C, and very distressed by docs 🙂 Currently I try to create C-struct in KN function and return it to C-function
o
Exactly what happens in sample above
r
Yes, I see. Thank you!