0
Ich versuche, czmq mit Scala-native zu verwenden, und ich habe keine Möglichkeit gefunden, Zeiger in Scala-native zu erstellen.Zeiger auf Zeiger in Scala-native
hier ist extern:
@native.link("czmq")
@native.extern
object czmq {
//struct _zsock_t {
// uint32_t tag; // Object tag for runtime detection
// void *handle; // The libzmq socket handle
// char *endpoint; // Last bound endpoint, if any
// char *cache; // Holds last zsock_brecv strings
// int type; // Socket type
// size_t cache_size; // Current size of cache
// uint32_t routing_id; // Routing ID for server sockets
//};
type zsock_t = native.CStruct7[
native.CUnsignedLongLong,
native.Ptr[Byte],
native.CString,
native.CString,
native.CInt,
native.CSize,
native.CUnsignedLongLong]
def zsock_new_push(endpoint: native.CString): native.Ptr[zsock_t] = native.extern
def zsock_new_pull(endpoint: native.CString): native.Ptr[zsock_t] = native.extern
def zstr_send(dest: native.Ptr[Unit], str: native.CString): native.CInt = native.extern
def zstr_recv(src: native.Ptr[Unit]): native.CString = native.extern
//void zsock_destroy (zsock_t **self_p)
def zsock_destroy(self_p: native.Ptr[native.Ptr[zsock_t]]):Unit = native.extern
}
und hier meine einfache Haupt-Methode ist:
object Main {
def main(args: Array[String]): Unit ={
val push = czmq.zsock_new_push(c"inproc://example")
val pull = czmq.zsock_new_pull(c"inproc://example")
czmq.zstr_send(push.cast[Ptr[Unit]], c"Hello World")
val s = fromCString(czmq.zstr_recv(pull.cast[Ptr[Unit]]))
println("msg: "+s)
czmq.zsock_destroy(push) // doesn't compile
czmq.zsock_destroy(pull) // doesn't compile
}
}
Die Frage ist also, wie man mit &
push
und pull
Variablen Zeiger wie in c zu machen?