From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id B4BF3BDCB for ; Thu, 8 Sep 2005 18:31:06 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j88GV65I018782 for ; Thu, 8 Sep 2005 18:31:06 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA09869 for ; Thu, 8 Sep 2005 18:31:05 +0200 (MET DST) Received: from smtp.cegetel.net (mf00.sitadelle.com [212.94.174.67]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j88GV5X7018778 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Thu, 8 Sep 2005 18:31:05 +0200 Received: from [192.168.144.2] (unknown [84.5.107.164]) by smtp.cegetel.net (Postfix) with ESMTP id 08D131A4844; Thu, 8 Sep 2005 18:31:01 +0200 (CEST) Message-ID: <43206744.5090907@univ-savoie.fr> Date: Thu, 08 Sep 2005 18:31:00 +0200 From: Christophe Raffalli User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: fr, en MIME-Version: 1.0 To: caml-list Subject: announce: callbacks-0.1 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4320674A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43206749.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; christophe:01 raffalli:01 christophe:01 raffalli:01 univ-savoie:01 lama:01 univ-savoie:01 callbacks:01 ocaml:01 bindings:01 ocaml:01 mli:01 val:01 int-:01 int-:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 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; } ...