caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
To: Paolo Donadeo <p.donadeo@gmail.com>
Cc: OCaml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Binding the Lua library [was: adding a scripting language to an ocaml program]
Date: Tue, 06 Jul 2010 23:28:03 +0200	[thread overview]
Message-ID: <4C339FE3.6000402@citycable.ch> (raw)
In-Reply-To: <AANLkTinP-LJgo4Ehy-eO0LRAOsrCGDKQ78OSQNdA8eGz@mail.gmail.com>

Paolo Donadeo a écrit :
> 
> So I wrote the binding to some basic functions and a stress test
> designed to reveal memory leaks of the binding. The test passed and so
> I consider the code quite stable, but I had to stop the development
> due to the chronic lack of time and due to a specific problem: I don't
> know how to handle the impedance mismatch between the two garbage
> collectors.

Yes. This kind of issue is tough. I also had it in the OCaml-R code. And 
the solution is far from perfect, but works. I do not know about Lua, 
though.

> And again: how to translate (read: how to bind) in OCaml functions like these:
> 
> void *lua_newuserdata (lua_State *L, size_t size); [4]
> or
> void *lua_touserdata (lua_State *L, int index); [5]
> 
> Is Obj.magic the only possible way? It's ugly and, of course,
> "Obj.magic is not part of the OCaml language", but in this case you
> use a cast in C, so why not cast a spell in OCaml?

You might want to check out the code sample I published here (at the 
bottom).

	http://ocaml.janestreet.com/?q=node/59

Unfortunately, using this recursive subtyping trick (which can be 
extended to more sophisticated recursive subtyping between more than 2 
type systems) raises issues in the presence of OCaml classes: The 
compiler goes in an infinite loop when doing type inference. The issue 
should be solved in 3.12.

It's not yet used in the OCaml-R binding because of compiler infinite 
loop problem. But it is used in my (unpublished) Python binding.

> If anyone is interested in my prototype I could clean up the source,
> remove comments in Italian and publish it on GitHub or OCamlCore.

I'm always interested in language bindings... And I think a few other 
people are interested in an Lua binding.

> And, of course, any ideas or help on the garbage collector(s) issue are welcome.

I do not know much about Lua's GC. My experience (for R, Python and 
Java) is that it's doable. The first shot is often imperfect and 
inefficient becauses GCs are not designed in the spirit of being binded. 
(R's API only provides a cumbersome stack-based mechanism to interact 
with R's GC, which is wholly inadequate).

I guess that with more available time, it is indeed possible to do clean 
tricks in order to get the GCs to cooperate efficiently... (I have a few 
tricks in mind for R that will have to wait.)

All the best,

-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/


  reply	other threads:[~2010-07-06 21:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-05 22:32 Paolo Donadeo
2010-07-06 21:28 ` Guillaume Yziquel [this message]
2010-07-07 13:50   ` Sylvain Le Gall
2010-07-07 16:30     ` [Caml-list] " Martin DeMello
2010-07-07 21:01     ` Paolo Donadeo
2010-07-07 22:03       ` Paolo Donadeo
2010-07-07 20:36   ` [Caml-list] " Paolo Donadeo
2010-07-07 20:48     ` Török Edwin
2010-07-07 21:11       ` Paolo Donadeo

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=4C339FE3.6000402@citycable.ch \
    --to=guillaume.yziquel@citycable.ch \
    --cc=caml-list@yquem.inria.fr \
    --cc=p.donadeo@gmail.com \
    /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).