Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ffi.callback

import ffi.callback

ffi lifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelled ffi.callback.* needs import ffi.callback.

Zuri functions that C can call.

Classes

Callback

class ffi.Callback

A Zuri function behind a C function pointer, made by ffi.callback().

A callback lives until release(). Nothing else frees it, because nothing can know when the C library has finished with the pointer; a callback that is never released is kept for the life of the program, and so is the function behind it.

A Zuri function passed straight to a function-pointer parameter needs none of this: it becomes a callback for the length of that one call. Make one explicitly when C keeps the pointer past the call.

  • printable — has a @to_string(), so echo and print() show something useful

Constructor

ffi.Callback()

Callback.pointer()

ffi.Callback.pointer() -> Pointer

The C function pointer, typed with the callback’s signature.

Returns Pointer

Raises CallbackError when the callback has been released.

Callback.type()

ffi.Callback.type() -> Type

The callback’s type: a pointer to its function type.

Returns Type

Callback.release()

ffi.Callback.release()

Frees the callback’s code and lets go of its function.

C must not call the pointer again. Passing the callback to a foreign function after this raises CallbackError; a call C still makes through a pointer it kept is undefined, exactly as a call through any freed function pointer is. Releasing twice does nothing.

Callback.is_released()

ffi.Callback.is_released() -> bool

Whether release() has been called.

Returns bool

Callback.to_string()

ffi.Callback.to_string()

2026, Richard Ore and Zuri contributors