I want to write a small wrapper library for a C library (ZeroMQ v3, to be more specific).
I wonder, however, how to declare foreign nested structs and unions in CFFI.
The C header file containing the respective struct/union combination can be found here.
CFFI’s documentation couldn’t help so far and I also couldn’t find similar questions online yet.
I’ll be glad for any help!
defcstructcan be used in this case. Also, in the docs you’ll find examples of defining a foreign struct, and also that the two kinds of slots possible are simple (types such as:int) and aggregate (the name of other struct), so nothing prevents you to be defining the different structures that form that big union and then compose the union (there is also adefcunionconstruct).The own CFFI implementation has examples and tests for structs like this:
Note that
a-s-shortis of types-short, defined above.