From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 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 7563EBCBF for ; Mon, 21 Aug 2006 11:16:51 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k7L9GoRt016951 for ; Mon, 21 Aug 2006 11:16:51 +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 LAA18851 for ; Mon, 21 Aug 2006 11:16:50 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k7L9Glr9016928 for ; Mon, 21 Aug 2006 11:16:49 +0200 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id k7L9GbiV014589; Mon, 21 Aug 2006 18:16:37 +0900 (JST) Date: Mon, 21 Aug 2006 18:14:42 +0900 (JST) Message-Id: <20060821.181442.124866554.garrigue@math.nagoya-u.ac.jp> To: micha-1@fantasymail.de Cc: caml-list@inria.fr Subject: Re: [Caml-list] question about caml_get_public_method From: Jacques Garrigue In-Reply-To: <20060821071532.32660@gmx.net> References: <20060821071532.32660@gmx.net> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 44E97A02.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 44E979FF.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 camlcvs:01 cvsweb:01 bazar-ocaml:01 lablgl:01 def:01 caml-list:01 ids:01 ids:01 argument:02 caml:02 caml:02 callback:02 callback:02 From: "Michael Wohlwend" > 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. http://camlcvs.inria.fr/cgi-bin/cvsweb/bazar-ocaml/lablGL/src/var2def.ml?rev=1.9 The 1st approach should work too. Jacques Garrigue