Lyricdev
GitHub

class Callback

pub class Callback<C>

A Lyric closure C calls, with its state: C's void *userdata beside a function pointer.

C is the C function's type as C calls it, extern "C" fn(…) -> T; its first or its last parameter is the Ptr<void> that C hands back, and the closure takes the others — Callback<extern "C" fn(Ptr<void>, int) -> void>.new((event) => { seen += event; }), handed to C as on_event(cb.function, cb.userdata).

The closure stays alive until Callback.release — C may call it as long. C calls it on the thread Lyric runs on, as any function C calls; one that returns nothing may be called on a thread of C's own too, and goes to the thread that made it, which runs it in its scheduler's next turn — with what C passed, while C's thread goes on.

Fields

pub function: C

The pointer C calls: it finds the closure through Callback.userdata.

pub userdata: Ptr<void>

What C hands back to Callback.function: the closure's handle.

Methods

pub static fn new(_closure: C): Callback<C>

Returns the callback for the closure it is given, a function of the parameters of C but its userdata. The compiler writes the function C calls; this body never runs.

pub mut fn release(): void

Lets the closure go: after it C must not call Callback.function again.

Panics

Where the callback was released already.