package pyml

  1. Overview
  2. Docs

Embedding of OCaml values in Python.

type 'a t = {
  1. wrap : 'a -> Object.t;
  2. unwrap : Object.t -> 'a;
}
val check : Object.t -> bool

check v returns true if v contains an OCaml value.

val create : string -> 'a t

For a given type 'a, create s returns a pair { wrap; unwrap }. wrap v transforms the value v of type 'a to an opaque Python object. unwrap w transforms the opaque Python object w previously obtained with wrap v into the original OCaml value v, such that unwrap (wrap v) = v. Failure _ is raised if a wrapper has already been generated for a type of the same name.

val make : string -> ('a -> Object.t) * (Object.t -> 'a)

Same as create, but returns a plain pair instead of a record.

val type_of : Object.t -> string

type_of w returns the type string associated to the opaque Python object w.

val is_valid : Object.t -> string -> bool

Wrapper for PyCapsule_IsValid. OCaml capsules have the name "ocaml-capsule". We have check v = is_valid v "ocaml-capsule".

val unsafe_wrap_value : 'a -> Object.t

unsafe_wrap_value v transforms the value v to an opaque Python object.

val unsafe_unwrap_value : Object.t -> 'a

unsafe_unwrap_value v transforms the opaque Python object w previously obtained with unsafe_wrap_value v into the original OCaml value v.

OCaml

Innovation. Community. Security.