[ocaml-ctypes] Defines, and Structs with platform-specific fields
Daniel Bünzli
daniel.buenzli at erratique.ch
Mon Oct 20 16:47:51 BST 2014
Le lundi, 20 octobre 2014 à 17:28, Trevor Smith a écrit :
> Jeremy -- I like the functor idea + first class modules: it is elegant. However I agree with Daniel's point about maintainability.
>
> If I use the allocate w/ a c function that returns the size of the struct I will be good to go. Then have ctypes reference public fields and make strong wording in the implementation to never allocate a ctype struct using make.
Keep all these things abstract from OCaml's point of view: we don't want to program in C, we want to program in OCaml. Treat each struct pointer as an abstract type and defines getter/accessors and creation functions on values of these type. Don't make any of the ctypes types leak in the interface.
See for example the way I handled the SDL_Event type which is a union of many structs:
http://hg.libsdl.org/SDL/file/704a0bfecf75/include/SDL_events.h#l498
Here:
http://erratique.ch/software/tsdl/doc/Tsdl.Sdl.Event.html
https://github.com/dbuenzli/tsdl/blob/bc18d14b1a28af99ebc30b61e303ee5304055d31/src/tsdl.ml#L3287
Best,
Daniel
More information about the Ctypes
mailing list