And how can I use ByteArray? ```e: /home/commander...
# kotlin-native
i
And how can I use ByteArray?
Copy code
e: /home/commandertvis/IdeaProjects/communicator/communicator-zmq-c-transport/src/nativeMain/kotlin/Server.kt: (22, 43): type @[ParameterName(name = 'argument')] kotlin.ByteArray  is not supported here: doesn't correspond to any C type
a
Something like that:
Copy code
val buffer = ByteArray(4096)
val scan = fgets(buffer.refTo(0), buffer.size, fp)
i
What's the way to get byte array from the C?
a
What do you want? Have you got some result from C code? Or you have to call some C code with ByteArray?
i
I want to acquire a C function with the signature similar to
(argument: ByteArray, invariant: COpaquePointer) -> ByteArray
a
I don’t know how it has to look like. But you cat try to do: 1. call C function with this argument and inline static function like
Copy code
return MHD_start_daemon( staticCFunction { _, addr, addrLen -> ... }, ... )
2. Introduce variable> You will see something like
Copy code
val apc = staticCFunction<COpaquePointer?, CPointer<sockaddr>?, socklen_t, MHD_Result>
i
No, I've meant "to receive such a function from C"
a
Have you got a C-function with return type “function”?
i
I want to write a Kotlin function taking a callback from C with the signature
(argument: ByteArray, invariant: COpaquePointer) -> ByteArray
.
a
How are you taking a callback from C?
i
As CPointer<CFunction<(argument: ByteArray, invariant: COpaquePointer) -> ByteArray>>. However, in the generated header the type of that parameter is void*
a
Copy code
fun register(f: CPointer<CFunction<(argument: ByteArray, invariant: COpaquePointer) -> ByteArray>>) {
    }
    
    fun x() {
        register(staticCFunction { t, _ -> ByteArray(12) })
    }
Ok?
i
message has been deleted