Next: , Previous: , Up: Top   [Contents][Index]


2 A More Detailed Example

In this chapter we’ll walk through the process of wrapping an increasingly complex C API. In the process, we’ll try to hit all the important G-Wrap features.

You’ll see how to define a wrapset, add new types to it (when the default set of types isn’t sufficient), wrap the C-side functions, and then generate the Guile wrapper code from the wrapset definition.

To start, let’s presume you want to wrap a C interface that initially looks like this:

  char*  join_strings(char *a, char *b);
  double seconds_since_dow(unsigned int day_of_the_week);

and you want to call your wrapset “miscutils”.

To define your module, you need to create a wrapper specification, which normally consists of deriving from the <gw-wrapset> class and providing an initialize method that adds the to-be-wrapped functions and types. Conventionally, if you’re creating a wrapper module named "foo", the wrapset specification file would be named foo-spec.scm, or placed in separate ws/ subdirectory.