fdopen / ctypes-zarith

Demo how to mix ctypes and "custom" OCaml types
Other
4 stars 5 forks source link

Initializing MPQ.zarith in C structure? #3

Open akshajgaur opened 4 years ago

akshajgaur commented 4 years ago

I am created inverted bindings. I have a structure in C where one of the elements is a rational number. I defined it in a struct in OCaml as MPQ.zarith, and in C, it is

mpq_ptr x

I was wondering how I could intitialize this field in c, and pass a value to OCaml. I haven't found much documentation. I tried to expose it as a void pointer, but it couldn't receive an input from c. Is defining a struct that has an rational number as simple as this? Or is there more to it.

  let x : [`x] structure typ = structure "x"
  let y = field x "z" (MPQ.zarith)
  let () = seal x
fdopen commented 4 years ago

Did you try it out and encounter a problem?

See https://github.com/fdopen/ocaml-ctypes-inverted-stubs-example/tree/zarith