1

I am wrapping a C API in scala using scala-native, however the C API expects the user to provide callback for signalling through the API:

 void set_terminate (void * solver, void * state, int (*terminate)(void * state));

The callback is periodically called to check if the API process must be interrupted.

I would like to wrap it to this sig in

def setTerminate[A](
      state: A,
      terminate: native.CFunctionPtr1[A, native.CInt] ): Unit = {
      ipasir_set_terminate(solver, state, terminate)
    }

I saw that there were some implicit conversions from scala to native defined in the nativelib.scala

https://github.com/scala-native/scala-native/blob/master/nativelib/src/main/scala/scala/scalanative/native/CFunctionPtr.scala

But I have failed to understand how this works, and how to perform erasure from A to native.Ptr[Byte]

Any help appreciated

remi
  • 566
  • 3
  • 13

0 Answers0