English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Unset or remove an OCaml callback registration
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-04-03 (14:08)
From: Hezekiah M. Carty <hcarty@a...>
Subject: Re: [Caml-list] Unset or remove an OCaml callback registration
On Thu, 03 Apr 2008, Jacques Garrigue wrote:

> From: "Hezekiah M. Carty" <hcarty@atmos.umd.edu>
> > Is this possible, either from the C or OCaml side without making the
> > callback associate with "foo" an option type (use (Callback.register
> > "foo" (Some some_func)) to set a callback and (Callback.register "foo"
> > None) to clear it)?
> Since Callback.register has type: string -> 'a -> unit
> you are not limited by the ocaml type system.
> So you can reset your value with
>   Callback.register "foo" 0
> and check for equality with Val_int(0) on the C side.
> (Note that you must initialize the value to 0 at program startup,
> because the default for an unitialized value is 0 which is not
> Val_int(0))

If I wrap the C interface in an OCaml module, would it be enough to

let () = Callback.register "foo" 0

in the top level of the module to have this command execute when the
module is loaded?  Or does the module user have to do some explicit

Thank you very much for the response,