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
question about caml_get_public_method
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-08-21 (09:16)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] question about caml_get_public_method
From: "Michael Wohlwend" <micha-1@fantasymail.de>

> if I want to connect a c++ method to a method of an ocaml class, I can choose between:
> a) in the initializer of the ocaml class use register_value to register a method (like self#some_method) and then calling an external function which caches the registered value and calls that method
> or
> b) calling an external function with the ocaml object as argument and then  use caml_get_public_method, cache the method-id of the callback methods and use those to make the callback.
> Is this just a matter of taste which one to use?

The second approach is going to be slightly simpler (no need to split
registration code between ocaml and C++, and the method ids do not
depend on the object/class.) Note that you don't really need to cache
the method itself, as caml_get_public_method is really fast.
You can also generate the method ids beforehand, avoiding need for any
cacheing. Here is a tool to do that.
The 1st approach should work too.

Jacques Garrigue