https://kotlinlang.org logo
i

Iaroslav Postovalov

03/01/2021, 6:27 PM
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

aleksey.tomin

03/02/2021, 2:54 AM
Something like that:
Copy code
val buffer = ByteArray(4096)
val scan = fgets(buffer.refTo(0), buffer.size, fp)
i

Iaroslav Postovalov

03/02/2021, 5:48 AM
What's the way to get byte array from the C?
a

aleksey.tomin

03/02/2021, 5:51 AM
What do you want? Have you got some result from C code? Or you have to call some C code with ByteArray?
i

Iaroslav Postovalov

03/02/2021, 6:02 AM
I want to acquire a C function with the signature similar to
(argument: ByteArray, invariant: COpaquePointer) -> ByteArray
a

aleksey.tomin

03/02/2021, 6:06 AM
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

Iaroslav Postovalov

03/02/2021, 6:15 AM
No, I've meant "to receive such a function from C"
a

aleksey.tomin

03/02/2021, 7:45 AM
Have you got a C-function with return type “function”?
i

Iaroslav Postovalov

03/02/2021, 8:09 AM
I want to write a Kotlin function taking a callback from C with the signature
(argument: ByteArray, invariant: COpaquePointer) -> ByteArray
.
a

aleksey.tomin

03/02/2021, 8:10 AM
How are you taking a callback from C?
i

Iaroslav Postovalov

03/02/2021, 8:14 AM
As CPointer<CFunction<(argument: ByteArray, invariant: COpaquePointer) -> ByteArray>>. However, in the generated header the type of that parameter is void*
a

aleksey.tomin

03/02/2021, 8:21 AM
Copy code
fun register(f: CPointer<CFunction<(argument: ByteArray, invariant: COpaquePointer) -> ByteArray>>) {
    }
    
    fun x() {
        register(staticCFunction { t, _ -> ByteArray(12) })
    }
Ok?
i

Iaroslav Postovalov

03/02/2021, 8:43 AM
message has been deleted
6 Views