As seen in See A Simple Example, wrapping a C function using G-Wrap’s
high-level functions is relatively simple. Essentially, it boils down
to a call to the
wrap-function! GOOPS method.
Add the C function described by args to the list of functions to
be wrapped by wrapset. The arguments in args must contain
the following named parameters (see
(ice-9 optargs) in The GNU Guile Reference Manual):
the symbol which should be bound to the wrapped function in Scheme at runtime.
the symbol naming the G-Wrap wrapped type of the C function result.
a string giving the C function’s name.
a list of the C function’s arguments where each element is of the form (more details below).
a string describing the function; this string may contain Texinfo markup.
The argument list which is passed as the
parameter consists of a list of argument specifiers. Each
argument specifier is itself a two-element list where:
The type specifier may in turn be one of the following:
if the parameter in question is an input parameter;
if the parameter in question is an output parameter;
if the parameter in question is a C pointer that points to memory controlled by the caller;
if the parameter in question is a C pointer that points to memory whose control is passed to the callee (FIXME: give an example);
if the Scheme input parameter is to be converted to a C pointer, then
let G-Wrap know that
#f is a valid value for this parameter;
#f will translate to the
NULL pointer in C;
if the parameter in question points to a C object that is
aggregated by the object returned by the function being wrapped
(more on this below). By object returned, we mean a wrapped C
pointer or WCP (see Wrapping a C Pointer Type) that is either
the return value or an
To illustrate this, here is an example of a valid argument description
mchars will be detailed later on, see C Types Provided in the Standard Wrapset):
'(((mchars null-ok caller-owned) input-string) (long input-integer) ((double out) output-floating-point))
Examples of valid usage patterns of
available in See Creating a Wrapper Module.