I've had a look at chapter 12 of the O'Rielly book as well as the
wrapper for ocaml-fftw3 and cairo-ocaml and it all seems a little
daunting.
I was wondering if there was any semi-automated too for creating
Ocaml bindings for C libraries.
Any pointers appreciated.
Cheers,
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo
+-----------------------------------------------------------+
"Lumping configuration data, security data, kernel tuning parameters,
etc. into one monstrous fragile binary data structure is really dumb."
- David F. Skoll
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
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
> One problem with such automated tools is that they have no clue of
> which C function takes time and which returns almost instantly.
Thanks a lot for this remark.
I'm also wondering how good automatic tools are for taking advantage of
Caml's rich typing system and of Caml features like exceptions.
An example will probably make my question more clear.
How would an automatic tool bind the open(2) function that returns either a
file descriptor (on success), or -1 to report failures, the precise reason
for the failure being contained in the errno variable. Would it be possible
to specify, with an automatic tool, that the returned valid is an int
unless open returns -1, in which case an error should be
reported through an exception ?
Or would an automatic tool bind open to a function returning an int in any
case, the task of testing the returned value having then to be performed
by the programmer, but in Caml ?
Sébastien.
Obviously there are some semi-automated ways, such as SWIG and camlidl
mentioned already. But I would definitely urge you to look at doing
the wrapping by hand. It's really not that hard, although you should
pay careful attention to ch18 of the manual.
Rich.
ch18: http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html
--
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Internet Marketing and AdWords courses - http://merjis.com/courses - NEW!
Merjis blog - http://blog.merjis.com - NEW!
Daniel
[1] <http://wwwfun.kurims.kyoto-u.ac.jp/soft/lsl/lablgl.html>