From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA22698; Tue, 20 Jul 2004 19:09:21 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA22283 for ; Tue, 20 Jul 2004 19:09:20 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from postfix3-2.free.fr (postfix3-2.free.fr [213.228.0.169]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i6KH9JEV021108 for ; Tue, 20 Jul 2004 19:09:19 +0200 Received: from univ-savoie.fr (grenoble-1-62-147-75-173.dial.proxad.net [62.147.75.173]) by postfix3-2.free.fr (Postfix) with ESMTP id 3EC0EC524; Tue, 20 Jul 2004 19:09:17 +0200 (CEST) Message-ID: <40FDA63B.8020306@univ-savoie.fr> Date: Tue, 20 Jul 2004 19:09:47 -0400 From: Christophe Raffalli User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040115 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Olivier Andrieu Cc: caml-list@inria.fr Subject: Re: [Caml-list] Calback References: <40FC0BEF.4080909@univ-savoie.fr> <3B84CC2A-D97E-11D8-A7B0-00039310CAE8@inria.fr> <40FD79F9.6040309@univ-savoie.fr> <20040720.164053.104046716.andrieu@ijm.jussieu.fr> In-Reply-To: <20040720.164053.104046716.andrieu@ijm.jussieu.fr> X-Enigmail-Version: 0.83.3.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at nez-perce with ID 40FD51BF.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; raffalli:01 raffalli:01 univ-savoie:01 caml-list:01 callback:01 sizeof:01 sizeof:01 glsurf:01 callback:01 callbacks:01 val:01 milliseconds:01 val:01 camlprim:01 camlprim:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > static void glutTimerFunc_cb(int fun_arg) > > { > > // fun_arg is a pointer on a caml pair hidden in an integer. > > // Moreover we remove the global root because each callback is used once > > // by the timer. > > value *v = (value) fun_arg; > > I'm afraid this will break on plaforms where `sizeof (int) != sizeof (long)'. > Anyway, for GlSurf, I am just using this (which is faster) and for most case I think this a the right code (except that set_timer should raise an exception it init_timer was not called previously). This code allow to change the callback associated with timers but does not allow to have two timers with different callbacks. But the later is only usefull (in GLUT) for timers, all other callback could use code similar to this. -- ML ------------------------------- (* init_timer f set the function to be called by all timer *) external init_timer : (value:int -> unit) -> unit = "myinit_glutTimerFunc" (* set_timer ms val : set a timer in ms milliseconds calling the function registered by init_timer with val as argument *) external set_timer : int -> int -> unit = "myml_glutTimerFunc" -- C -------------------------------- static value* caml_glutTimerFunc_cb = NULL; static void myglutTimerFunc_cb(int val) { leave_blocking_section (); callback (*caml_glutTimerFunc_cb, Val_int(val)); enter_blocking_section (); } CAMLprim value myml_glutTimerFunc(value millis_val, value v) // set Timer callback { glutTimerFunc(Int_val(millis_val), &myglutTimerFunc_cb, Int_val(v)); return Val_unit; } CAMLprim value myinit_glutTimerFunc(value v) { if (caml_glutTimerFunc_cb) { caml_remove_global_root(caml_glutTimerFunc_cb); } else { caml_glutTimerFunc_cb = (value*) malloc(sizeof(value)); } *caml_glutTimerFunc_cb = v; caml_register_global_root(caml_glutTimerFunc_cb); return Val_unit; } -- Christophe Raffalli Université de Savoie Batiment Le Chablais, bureau 21 73376 Le Bourget-du-Lac Cedex tél: (33) 4 79 75 81 03 fax: (33) 4 79 75 87 42 mail: Christophe.Raffalli@univ-savoie.fr www: http://www.lama.univ-savoie.fr/~RAFFALLI --------------------------------------------- IMPORTANT: this mail is signed using PGP/MIME At least Enigmail/Mozilla, mutt or evolution can check this signature --------------------------------------------- ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners