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 8DBAEBDCB for ; Thu, 8 Sep 2005 23:24:11 +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 j88LOACV011065 for ; Thu, 8 Sep 2005 23:24:11 +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 XAA13907 for ; Thu, 8 Sep 2005 23:24:10 +0200 (MET DST) Received: from smtp.cegetel.net (mf01.sitadelle.com [212.94.174.68]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j88LOA7E011061 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Thu, 8 Sep 2005 23:24:10 +0200 Received: from [192.168.144.2] (unknown [84.5.107.164]) by smtp.cegetel.net (Postfix) with ESMTP id 93F693F25D3; Thu, 8 Sep 2005 23:24:07 +0200 (CEST) Message-ID: <4320ABF7.7020009@univ-savoie.fr> Date: Thu, 08 Sep 2005 23:24:07 +0200 From: Christophe Raffalli User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: fr, en MIME-Version: 1.0 To: Maas-Maarten Zeeman , caml-list Subject: Re: [Caml-list] announce: callbacks-0.1 References: <43206744.5090907@univ-savoie.fr> <4320A68E.1060608@xs4all.nl> In-Reply-To: <4320A68E.1060608@xs4all.nl> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 4320ABFB.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4320ABFA.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 caml-list:01 lama:01 univ-savoie:01 ocaml:01 callbacks:01 ocaml:01 ocaml-values:01 bindings:01 bug:01 bindings: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 Maas-Maarten Zeeman a écrit : > > Hello, > >> link: third item of: >> >> http://www.lama.univ-savoie.fr/~raffalli/?page=soft&lang=en >> >> comment and idea are welcome ! >> > > Sounds like a nice idea. As the author of ocaml-expat a binding I've > also worked with c -> ocaml callbacks. > > It is not really clear to me what problem you are trying to solve. It is > not very difficult for somebody writing a Ocaml binding to come up with > a solution which is easy to call an ocaml function value from c. > > What I did was create one fixed c-callback functions which: > > receive c-parameters > transform them to ocaml-values > lookup the ocaml callback "cb" in a tuple (set earlier from ocaml), This is that step I want to avoid ... not mainly for performance, but because there are some cases where you do not know which callback you should call (this was the case for one of the glut callback, I don't recall which one, and it was a bit tricky for glutTimer). It happens that in glut, the current window or current menu is properly set before calling the callback ... but there may be other library, more purely functional, with no concept of "current window" ... The other reason, is that it makes it easier to writte the bindings for the library (no thinking required and therefore less bug) ! and does not make it that much complex for the user. If you really need "dynamic" callback with arbitrary closure, then you can implement your trick above mine in OCaml. By expending my work, we could write and use bindings for a C library like glut without writing a line of C, except to convert data structure from C to OCaml if you really need that. This could divide the size of the glut binding by a factor 2 or 3 ... which is important ! > apply cb to the ocaml-values, > etc, etc > > The ocaml programmer just has to deal with normal ocaml callback > function values (which can be partially applied, unnamed, etc). These > will be stored via c in a tuple. The value pointing to this tuple is > registered as 1 global root. If you have large amounts of callbacks it > would probably work with a simple hash table too. Then you only have to > write/generate 1 c-callback function (per c-signature) which takes care > of calling an unlimited amount of caml callbacks. > > Its interesting to have the c-wrapper function generated as it would > prevent hard to debug gc problems. > > Regards, > > Maas