caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Raffalli <christophe.raffalli@univ-savoie.fr>
To: caml-list <caml-list@inria.fr>
Subject: announce: callbacks-0.1
Date: Thu, 08 Sep 2005 18:31:00 +0200	[thread overview]
Message-ID: <43206744.5090907@univ-savoie.fr> (raw)

link: third item of:

http://www.lama.univ-savoie.fr/~raffalli/?page=soft&lang=en

comment and idea are welcome !

-----------
MOTIVATION
-----------

callbacks are problematic when writting OCaml bindings for C
library. Indeed, a C function waits for a function respecting C
calling conventions as argument, and OCaml functions do not respect the
C conventions.

Then in a library you only have a limited number of the C functions and
in fact ideally, it is the user of the library that should often write 
the C function that needs to be passed in arguments to other C functions.

This is too hard for the average user ... this is why I wrote this package


Here is an example on how to use it (see the README file for a more 
detailled doc)

--------------
in glut.mli:
--------------

open Direct_callback
...
val reshapeFunc: cb:(w:int->h:int->unit) callback->unit
...

-------------
in a programm using lablGlut
-------------

let doReshape ~w ~h =
   ...

c_wrapper doReshape_cb for  doReshape : w:int->h:int->unit
...

ReshapeFunc doReshape_cb
...


-------------
in glut.ml
-------------

open Direct_callback
...
external reshapeFunc : cb:(w:int->h:int->unit) callback->unit = 
"ml_glutReshapeFunc"
...

-------------
in wrapglut.c
-------------

...
ML_1(glutReshapeFunc,Callback2)
...

which expends to

...
CAMLprim value ml_glutReshapeFunc (value arg1) \
{ glutReshapeFunc ((void (*)(int,int))(arg1)); return Val_unit; }
...



             reply	other threads:[~2005-09-08 16:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-08 16:31 Christophe Raffalli [this message]
     [not found] ` <4320A68E.1060608@xs4all.nl>
2005-09-08 21:24   ` [Caml-list] " Christophe Raffalli
2005-09-08 23:31     ` Bardur Arantsson
2005-09-09  6:30       ` Bardur Arantsson
2005-09-10  7:04         ` [Caml-list] " Xavier Leroy
2005-09-10  7:31           ` Bardur Arantsson
2005-09-10 13:04           ` [Caml-list] " Yaron Minsky
2005-09-10 21:02           ` caml_register_unmutable_global_root Christophe Raffalli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43206744.5090907@univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).