Now we have all the enumerations and structures declared we now have to wrap the C functions. In general, to convert a C function declaration to Pyrex you:
cdef externto the beginning of the line,
;from the end of the line, and
Consider the following C function declaration.
xosd *xosd_init (char *font, char *colour, int timeout, xosd_pos pos, int offset, int shadow_offset);
It declares a function,
xosd_init, which takes
six arguments including one enumeration (
The Pyrex declaration of the same function looks very
cdef extern xosd *xosd_init(char *font, char *colour, int timeout, xosd_pos pos, int offset, int shadow_offset)
C, like Python, can handle variable length arguments. The conversion between C var-args and Pyrex var-args is fairly strait forward. Consider the function declaration:
int xosd_display (xosd *osd, int line, xosd_command command, ...);
After the three compulsory arguments (
command), the function
xosd_display can take a variable number of
To emulate this in Pyrex we also write ellipsis:
cdef extern int xosd_display(xosd *osd, int line, xosd_command command, ...)
Be warned, things get more complicated later on.
Call by reference is done in a similar way to call by value. Consider the following.
extern int cupsGetDests(cups_dest_t **dests);
dests will be modified when
In Pyrex, the call would look like the following.
cdef extern int cupsGetDests(cups_dest_t **dests)
We have to have declared the argument,
before we declared the function.