If you do not see a For-all sign at the first line, install unicode capable fonts.
What currently you can do:
You can call some of Python/C API functions from OCaml.
How to install:
How to use:
test.ml is for an example.
- api.ml provides the main Python/OCaml interface.
Use "open Opycaml.Api" in your OCaml programs.
Once opened, Python/ML API functions are available by
Py.<Class>.<function> names. For example,
Py.Object.repr for PyObject_Repr
Py.String.check for PyStrnig_Check
You can omit Py. prefix for the module names which do not collide
with OCaml standard library name space:
Object.repr for PyObject_Repr
(String is in OCaml standard library, so no short cut is available.)
- Do not forget calling Base.initialize for initialization.
- autoapi.ml is auto-created by CamlIDL. It provides almost of
all the available API functions in OPyCaml. Their comments are
from Python/C API reference, which are useful to understand them.
- api.ml extends autoapi.ml, providing things not easily done by
CamlIDL's code generator.
- A C function Py<Hoo>_<Bar> is mapped into an ML function Hoo.bar,
where the first letter of "Bar" is lowercased.
PyObject_Repr => Object.repr
PyString_Check => String.check
( Note that String module is available by Py.String )
There is one exception: If a C function has all-capital-or-underscore
postfix name, such as PyTuple_GET_ITEM, its ML function name is not
first letter lowercased but is prefixed by '_':
PyTuple_GET_ITEM => Tuple._GET_ITEM
OO style interface, OOApi.ml is now also provided. This module is automatically generated from api.ml.
See examples/testoo.ml for how to use.
- open Opycaml.OOApi at the beginning of your module
- The Api function calls like [Api.M.func m args] are in OO style in OOApi, [m#func args], if [m]'s an object of [M].
- If an Api function call [Api.M.func m args] has no trivial OO style translation, i.e. if [m] is not an object of [M], [OOApi.M.func] is available.
- For example,
let _ = Base.initialize ()
... Dict.getItemString dict "foobar" ...
becomes as follows in OO style:
let _ = Base.initialize () (* It has no trivial OO translation. *)
... dict#getItemString "foobar" ...
If you have js_of_ocaml installed, there is a small tool to use the syntax sugar of js_of_ocaml for Python dictionary access in OPyCaml. See js_of_ocaml directory.