From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q43DZuU0029088 for ; Thu, 3 May 2012 15:35:56 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap4BAH2Iok/ZSMDdkWdsb2JhbABFsnQiAQEBAQkLCwcUAySCCQEBBAEnEz8FCwshJQ8BBA0bIROHfgEDBgmwWB8rDYlTigaHAgSRP4oihVyHbQ X-IronPort-AV: E=Sophos;i="4.75,523,1330902000"; d="scan'208";a="142446473" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail4-smtp-sop.national.inria.fr with ESMTP; 03 May 2012 15:35:51 +0200 Received: from moweb002.kundenserver.de (moweb002.kundenserver.de [172.19.20.108]) by fmmailgate01.web.de (Postfix) with ESMTP id DBBD21AD5E84E for ; Thu, 3 May 2012 15:35:50 +0200 (CEST) Received: from frosties.localnet ([95.208.118.96]) by smtp.web.de (mrweb002) with ESMTPA (Nemesis) id 0LpOOj-1RwOfL21q9-00f7jO; Thu, 03 May 2012 15:35:50 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.77) (envelope-from ) id 1SPwCE-0006zL-00; Thu, 03 May 2012 15:35:50 +0200 From: Goswin von Brederlow To: Joel Reymont Cc: caml-list@inria.fr References: Date: Thu, 03 May 2012 15:35:49 +0200 In-Reply-To: (Joel Reymont's message of "Thu, 3 May 2012 13:22:49 +0100") Message-ID: <871un1z8sq.fsf@frosties.localnet> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Provags-ID: V02:K0:z2RzSHT1aBu1IPTI3IIIhs7833lfoW2MCuHoJ743fsV nduWeUZC/5qh3WrZdEsTMOJNbR8M6jU4OFCiL8dYh5UNFZivWZ Vb1r2pxZyRNMRvFOluCsr8XjCIIQL6CE0fSIV0sPDznYryvMEk TxTt/xKtNnumNtsyBXs4nUOadLBn3nRlye0h6tN/AGzorOj7ag fw+Nkz5zAOXNxzNb+Q2gw== Subject: Re: [Caml-list] using modules to wrap c++ classes Joel Reymont writes: > Suppose I have a C++ class with a bunch of methods that act as callbacks. > > My callbacks will be hit if I derive the class and implement the > methods I'm interested in. > > Now, I would like to wrap this class from OCaml. > > This is straightforward from using OCaml classes (section 18.3.5 of > the manual) but is there a way to implement this using modules? > > I don't think this is possible but would like to confirm. > > Thanks, Joel >From the top of my head: module M = struct type t external foo : t -> unit = "caml_mine_M_foo" end class M { void foo(void) { } }; value caml_mine_M_foo(value ml_m) { CAMLparam1(ml_m); M *m = (M*)ml_m; m->foo(); CAMLreturn Val_unit; } Wouldn't that do? It gets harder with inheritance, when you have modules A, B, C for the different classes and want to be able to pass a C.t to a function expecting a B.t. You will need to declare a C.as_b function and such. MfG Goswin