C function pointers that call x functions: a stub per callback, for a C library that takes a function pointer.
CallbackA C function pointer that calls an x function: (Callback make f nargs), then hand (cb address) to a C library that takes a function pointer.
The C caller passes up to four integer or pointer arguments; F gets each as an integer and answers the C result, #t as 1 and anything else that is not an integer as 0.
Keep the Callback while the library may call the address: it holds F, and the stub reaches F through its address.
An error raised in F unwinds through the C caller’s frames; a callback that can fail should catch its own errors.
targetThe function the stub calls: the one made with, answering its result as an integer
Field: data carried by a Callback instance.
nargsHow many arguments the C caller passes, 0 to 4
Field: data carried by a Callback instance.
asmThe assembler buffer the stub was written into, or nil between an image write and its load
Field: data carried by a Callback instance.
addressThe stub’s address, the integer to hand a C library; 0 between an image write and its load
Field: data carried by a Callback instance.
(remake!)Write the stub again – what the recache hook does after an image load; a consumer never needs to call it.
Instance method: called on a Callback instance.
Returns: INTEGER — The stub’s new address
(free!)Release the stub. The address is not callable afterwards.
Instance method: called on a Callback instance.
Returns: ANY — nil
(Callback make f nargs)A C function pointer that calls f: the stub is written and its address is (cb address).
Parameters:
CALLABLE — The x function to call, taking NARGS integersINTEGER — How many arguments the C caller passes, 0 to 4Returns: Callback — The callback
(Callback %door name)(Callback %write f nargs)