Callback(3)

πŸ’– Callback(3) β€” like, the OCaml library one, bestie πŸ’–

okay so this is <rainbow>Callback</rainbow> from the OCaml library man pages, and honestly? it's giving backstage-pass energy for your C code. stay with me 🫢


✨ NAME ✨

Callback β€” registering OCaml values with the C runtime</p>. that's the whole vibe. no cap.


πŸŽ€ Module πŸŽ€

the module is literally called Module Callback. yes bestie, that's the name, we don't question it πŸ’…


🌸 Documentation 🌸

so the signature is just:

Module Callback
 : sig end

and the one-line summary is, again, registering OCaml values with the C runtime. (they really said "say it twice, it's important" and honestly? iconic.)

here's the tea πŸ“: this module lets OCaml values get registered with the C runtime under a symbolic name, so that later on, your C code can call back registered OCaml functions, or raise registered OCaml exceptions. it's literally the group chat bridge between OCaml and C. iykyk πŸ”₯


πŸ’œ the functions πŸ’œ

  • val register : string -> 'a -> unit

Callback.register n v registers the value v under the name n. later, C code can retrieve a handle to v by calling caml_named_value(n). that's it, that's the whole slay ✨

  • val register_exception : string -> exn -> unit

Callback.register_exception n exn registers the exception contained in the exception value exn under the name n. later, C code can retrieve a handle to that exception by calling caml_named_value(n). and the exception value you get back this way is suitable for passing as the first argument to raise_constant or raise_with_arg. cute, functional, no notes 🧚

lowkey reminder bestie: caml_named_value(n) is the retrieval function in both cases, and the names you register under are the keys C uses to find your stuff. don't lose the name, or C is gonna be standing there like 😭

and that's the page!! πŸ¦‹ written by OCamldoc, dated 2026-06-22, and it's the Callback(3) page β€” go forth and register your values, bestie, you're the main character of the FFI now πŸ‘‘πŸ’–

πŸ“¦ where this page comes from