On 20 October 2014 21:46, Jeremy Yallop <[email protected]> wrote:
> This discussion is a useful reminder that ctypes really needs support
> for retrieving struct layout details from the declared API.  I'll look
> at how to add that support later this week and report back.

I've added support for retrieving struct layout from C in a pull request:

    https://github.com/ocamllabs/ocaml-ctypes/pull/62

It works in a very similar fashion to cstubs: you put your struct
declaration inside a functor

  module Bindings(S : Cstubs_structs.STRUCT) =
  struct
    open S
    let cell       = structure "cell"
    let payload = field cell int "payload"
    let next      = field cell (ptr cell) "next"
    let ()          = seal cell
  end

and then call Cstubs_structs.write_c to generate an ML module with
which to instantiate the functor.

The pull request has more details and some illustrative tests.
_______________________________________________
Ctypes mailing list
[email protected]
http://lists.ocaml.org/listinfo/ctypes

Reply via email to