Browse thread
Creating wrappers for C libraries
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Chris King <colanderman@g...> |
| Subject: | Re: [Caml-list] Creating wrappers for C libraries |
On 12/7/06, Erik de Castro Lopo <mle+ocaml@mega-nerd.com> wrote: > I was wondering if there was any semi-automated too for creating > Ocaml bindings for C libraries. I recently discovered that SWIG (http://www.swig.org/) supports O'Caml (though I haven't yet used it myself). If you're looking for speed though it may not be the best choice since all C types are mapped to one variant type in O'Caml. You can find O'Caml-specific docs here: http://www.swig.org/Doc1.3/Ocaml.html I presume you're looking to wrap libsndfile... I've wrapped a few similar libraries manually with very few problems. The libsndfile API looks to me like it should be fairly straightforward to wrap thanks to O'Caml's Bigarrays (plus you'll have lots of cut & paste). Start by writing a few simple integer, string, or array functions for O'Caml in C to get a feel for the API without having to worry about custom blocks and such. The curses wrapper in chapter 18 of the O'Caml manual is also a very good starting point. The custom block from that example can be used nearly verbatim for many C structures (such as SNDFILE *). I can provide you with the source of a couple other small wrappers if you like. Hope this helps, Chris