[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jacques Garrigue <garrigue@m...> |
| Subject: | Re: [Caml-list] Unset or remove an OCaml callback registration |
From: "Hezekiah M. Carty" <hcarty@atmos.umd.edu> > Is it possible to unregister a function or other value registered with > Callback.register? I use (Callback.register "foo" some_func) to > register coordinate transforms for a C library. If no callback is > registered for "foo" then a default transform is used by the C > library. I would like to be able to set and then remove the > association of some_func to the name "foo" at various points in my > program so that the C code will fall back on the default transform > (which does not require a callback and is much faster) when the named > callback "foo" is undefined or has been unregistered. > > 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)) Jacques Garrigue