Pycaml |
It is intended to allow users to build native ocaml libraries and use them from python, and alternately, in order to allow ocaml users to benefit from linkable libraries provided for python.
I created this library in order to take advantage of python binding for certain native libraries from ocaml. While it is true that I could have written new interfaces specifically for ocaml, the python interface is sufficient for my needs, and this project was easier.
Links:
Python | Objective Caml |
Note that used to be here: Ocaml 3.07 and Python 2.3 do not conflict, so you can avoid the earlier reported link-time conflict by using current versions of Ocaml and Python.
pycaml uses configure to find the python libraries, etc. Thanks to adonthell for their acinclude.m4.
Get the distribution here:pycaml.tar.gz
Because these are made to closely mirror the python API, the user should become familiar with the python API.
Given Ocaml parameter passing convention, it was convenient to pass multiple arguments as members of a tuple, but single arguments without. Consequently, functions with arity 1, such as pytuple_new are called as
pytuple_new 3 ;;
And functions with more arguments are called as
pydict_getitemstring (dict,"keystring") ;;
open Pycaml let foo_bar_print = pywrap_closure (fun x -> print_endline "hi" ; pynone ()) ;; let sd = pyimport_getmoduledict () ;; let mx = pymodule_new "CamlModule" ;; let cd = pydict_new () ;; let cx = pyclass_new (pynull (), cd, pystring_fromstring "CamlClass") ;; let cmx = pymethod_new (foo_bar_print,(pynull ()),cx) ;; let _ = pydict_setitemstring (cd, "CamlMethod", cmx) ;; let _ = pydict_setitemstring (pymodule_getdict mx, "CamlClass", cx) ;; let _ = pydict_setitemstring (sd, "CamlModule", mx) ;; let _ = pyrun_interactiveloop (0,"-") ;;