This package enables you to generate Julia bindings for OCaml libraries with no boilerplate.
To build and run the example, type the following at the root of this repo:
make testjl
In examples/libocaml/api.mli
, we find the following function declaration:
val evaluate: expr -> int
From this signature, the following C wrapper is generated automatically:
value* evaluate(value *x0) {
static const value *_f = NULL;
if (_f == NULL) _f = caml_named_value("evaluate");
value *_r = malloc(sizeof(value));
*_r = caml_callback_exn(*_f, *x0);
if (Is_exception_result(*_r)) {
caml_last_exception = Extract_exception(*_r);
caml_register_generational_global_root(&caml_last_exception);
free(_r);
return NULL;
}
else {
caml_register_generational_global_root(_r);
return _r;
}
}
Also, the following Julia stub is generated:
@caml evaluate(::Caml{:expr}) :: Caml{:int}
where the @caml
macro expands to:
function evaluate(e)
e = convert(Caml{:expr}, e)
GC.@preserve e begin
ptr = ccall((:evaluate, OCAML_LIB), Ptr{Cvoid}, (Ptr{Cvoid},), e.ptr)
return tojulia(Caml{:int}(ptr))
end
end