caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] boostbind/pythonbind/luabind for ocaml?
@ 2011-01-17 10:19 beo wulf
  2011-01-17 10:53 ` [Caml-list] " Sylvain Le Gall
       [not found] ` <20110117111304.GV4195@localhost>
  0 siblings, 2 replies; 4+ messages in thread
From: beo wulf @ 2011-01-17 10:19 UTC (permalink / raw)
  To: caml-list

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.

Thanks!

Note: Lua is written in C, not C++, and it still works fine -- as long
as there's a way / API to construct Ocaml objects in C-land. Template
magic does the rest.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Caml-list] Re: boostbind/pythonbind/luabind for ocaml?
  2011-01-17 10:19 [Caml-list] boostbind/pythonbind/luabind for ocaml? beo wulf
@ 2011-01-17 10:53 ` Sylvain Le Gall
       [not found] ` <20110117111304.GV4195@localhost>
  1 sibling, 0 replies; 4+ messages in thread
From: Sylvain Le Gall @ 2011-01-17 10:53 UTC (permalink / raw)
  To: caml-list

Hello,

On 17-01-2011, beo wulf <beowulf@intamp.com> wrote:
>   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.
>
> Thanks!
>
> Note: Lua is written in C, not C++, and it still works fine -- as long
> as there's a way / API to construct Ocaml objects in C-land. Template
> magic does the rest.
>

I am not sure it fits your needs, but there are OCaml bindings for Lua:
http://ocaml-lua.forge.ocamlcore.org

It should work but still need testing (and an official release).

Cheers,
Sylvain Le Gall
-- 
My company: http://www.ocamlcore.com
Linkedin:   http://fr.linkedin.com/in/sylvainlegall
Start an OCaml project here: http://forge.ocamlcore.org
OCaml blogs:                 http://planet.ocamlcore.org



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] boostbind/pythonbind/luabind for ocaml?
       [not found] ` <20110117111304.GV4195@localhost>
@ 2011-01-17 12:00   ` beo wulf
  2011-01-17 12:57     ` Guillaume Yziquel
  0 siblings, 1 reply; 4+ messages in thread
From: beo wulf @ 2011-01-17 12:00 UTC (permalink / raw)
  To: Guillaume Yziquel, caml-list

> 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.


> 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?

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:

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
(2) some sort of reference counting
(3) generating the code for the binding

(1) & (2) is already provided by pythonbind/luabind/slb
The question is (3) ... which I think can be automated once.

>
> And BTW, my codes do not work anymore because I've made big underlying
> changes that I haven't found the time to push forward.
>
> In a nutshell, for C++, it's hand-crafted. For Python, there's PyCaml.
>
> --
>     Guillaume Yziquel
> http://yziquel.homelinux.org
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] boostbind/pythonbind/luabind for ocaml?
  2011-01-17 12:00   ` [Caml-list] " beo wulf
@ 2011-01-17 12:57     ` Guillaume Yziquel
  0 siblings, 0 replies; 4+ messages in thread
From: Guillaume Yziquel @ 2011-01-17 12:57 UTC (permalink / raw)
  To: beo wulf; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-01-17 12:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-17 10:19 [Caml-list] boostbind/pythonbind/luabind for ocaml? 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 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).