[][src]Macro ocaml_interop::ocaml_call

macro_rules! ocaml_call {
    ( $(($obj:expr).)?$($fn:ident).+($gc:ident, $($arg:expr),+ $(,)?)) => { ... };
    ( $($path:ident)::+($gc:ident, $($args:expr),+ $(,)?) ) => { ... };
    ( $($path:ident)::+.$($field:ident).+($gc:ident, $($args:expr),+ $(,)?) ) => { ... };
}

Calls an OCaml function

The called function must be declared with ocaml!. This macro can only be used inside ocaml_frame! blocks, and the framce GC handle must be passed as the first argument to the function.

The result is either Ok(result) or Err(ocaml_exception) if an exception is raised by the OCaml function.

Examples

ocaml! { fn print_endline(s: String); }

// ...somewhere else inside a function
ocaml_frame!(gc, {
    let ocaml_string = to_ocaml!(gc, "hello OCaml!");
    ocaml_call!(print_endline(gc, ocaml_string)).unwrap();
});