[−][src]Macro ocaml_interop::ocaml_frame
Opens a new frame inside of which OCaml values can be rooted to have them tracked by the GC.
The first argument to this macro must a reference to an OCaml runtime handle.
The second argument is a list of "root variables" to reserve. These variables can
be used to "root" OCaml
values to obtain OCamlRef
values that can be used
to recover stale references to OCaml
values after calls to the OCaml runtime.
Examples
The following example reserves two root variables which are consumed to create two OCamlRef
values later used to retrieve two OCaml values after performing allocations through the OCaml runtime:
ocaml_frame!(cr, (hello_ocaml, bye_ocaml), { let hello_ocaml = to_ocaml!(cr, "hello OCaml!", hello_ocaml); let bye_ocaml = to_ocaml!(cr, "bye OCaml!", bye_ocaml); print_endline(cr, hello_ocaml); print_endline(cr, bye_ocaml); });