caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
To: beo wulf <beowulf@intamp.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] boostbind/pythonbind/luabind for ocaml?
Date: Mon, 17 Jan 2011 13:57:02 +0100	[thread overview]
Message-ID: <20110117125702.GW4195@localhost> (raw)
In-Reply-To: <AANLkTi=VBRLsTxBUtBPWqJNrSU5pXV6pKf9S29AM_HNv@mail.gmail.com>

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<int>
> std::vector<Foo>
> std::vector<Dog>
> 
> 
> > 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


      reply	other threads:[~2011-01-17 12:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-17 10:19 beo wulf
2011-01-17 10:53 ` [Caml-list] " Sylvain Le Gall
     [not found] ` <20110117111304.GV4195@localhost>
2011-01-17 12:00   ` [Caml-list] " beo wulf
2011-01-17 12:57     ` Guillaume Yziquel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110117125702.GW4195@localhost \
    --to=guillaume.yziquel@citycable.ch \
    --cc=beowulf@intamp.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).