From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p0HCwhJQ019022 for ; Mon, 17 Jan 2011 13:58:43 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtwDAC/LM01V2gB4h2dsb2JhbACkaAEBAQoLCAcTJMAkDYVDBI5d X-IronPort-AV: E=Sophos;i="4.60,332,1291590000"; d="scan'208";a="87117993" Received: from emailfrontal1.citycable.ch ([85.218.0.120]) by mail2-smtp-roc.national.inria.fr with SMTP; 17 Jan 2011 13:58:42 +0100 X-Alinto-smtpauth-localdomain: Yes Received: from seldon (unknown [85.218.92.99]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal1.citycable.ch (Postfix) with ESMTPA id 5836012C2DD; Mon, 17 Jan 2011 13:58:40 +0100 (CET) Received: from yziquel by seldon with local (Exim 4.72) (envelope-from ) id 1Peodq-0000dt-Qa; Mon, 17 Jan 2011 13:57:02 +0100 Date: Mon, 17 Jan 2011 13:57:02 +0100 From: Guillaume Yziquel To: beo wulf Cc: caml-list@yquem.inria.fr Message-ID: <20110117125702.GW4195@localhost> References: <20110117111304.GV4195@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p0HCwhJQ019022 Subject: Re: [Caml-list] boostbind/pythonbind/luabind for ocaml? Le Monday 17 Jan 2011 à 04:00:05 (-0800), beo wulf a écrit : > > Le Monday 17 Jan 2011 à 02:19:39 (-0800), beo wulf a écrit : > >> Hi! > >> > >>   Is there anything like luabind or pythonbind for Ocaml? Basically, it's > >> http://www.rasterbar.com/products/luabind/docs.html#hello-world > >>   a really convenient way to bind class member / functions to another language. > > > > For Python, there are PyCaml and my own stuff. PyCaml is the most > > supported, as long as you take Thomas Fischbacher's version and not the > > outdated version from Art Yerkes. > > I explained poorly. I don't want to bind lua or python to Ocaml. I > want to bind C++ to ocaml. There's what has been done with GCCXML for the Qt bindings. It seems to be broadly functional. Swig bindings are not really an option for something clean, unfortunately (in my opinion). > > For C, I'd suggest using encapsulate.macro.c from my OCaml-StdC. For > > C++, things are somewhat awkward. I've made a tentative binding to Boost > > stuff, but not really usable. The biggest issue is that C++ is more > > static when it comes to templates than OCaml, and OCaml is not dynamic > > enough as Python to cope for C++'s staticness. > > Can you expand on C++'s staticness, and why OCaml is not dynamic enough for it? Looking at Python bindings in Boost, it's somewhat surprisingly the dynamicness of Python that allows to easily map C++. OCaml lies too much inbetween in terms of staticness to have templates mapped right. > Luabind can't bind entire templates -- it can only bind instances of > templates. I'm perfectly happy accepting this lmitation, i.e. having > to have separte: Then this can be done. Automating it however, is more in the line of what has been for Qt. This limitation is a bit tough to accept in a language with polymorphism such as OCaml, though. I've been hard-pressed to find a workaround. > std::vector > std::vector > std::vector > > > > So for C++, you're almost better off making your bindings yourself. > > Binding a piece of code from C++ to anotehr langauge involves 3 steps > (1) template magic to get the type of the member/function Not so sure what you mean by 'magic'. I'd be interested. > (2) some sort of reference counting If you bind C++ to OCaml, yes, you can do that. If you want to have both directions, this approach doesn't work so well. You also have to keep in mind that OCaml's GC compacts the heap, so moves pointers. Keeping a hold on OCaml values from C++ in this context can be problematic. You often do not need to care about this if you're just importing code from C++ to OCaml, but you tend to get drawn fairly quickly into these considerations for non-trivial C++ libs. When you try to automate bindings with C++, you ran into more memory management issues than with C. Do you copy-construct into an OCaml value, do you only keep a pointer/reference? OCaml's memory moves around under the GC's impetus, and mixing smart pointer reference counting with OCaml's GC. All this makes it quite tough to go beyond something really naïve. > (3) generating the code for the binding As mentionned, the only potentially clean solution available for automating things, as far as I know is the Qt binding's GCC-XML stuff. > (1) & (2) is already provided by pythonbind/luabind/slb > The question is (3) ... which I think can be automated once. It probably 'can' be automated. -- Guillaume Yziquel