Next: , Previous: , Up: Basic Concepts   [Contents][Index]

3.1.2 Wrapped Types

Wrapped types are instances of the <gw-type> class and hold information about a C type being wrapped and how to wrap it. In See G-Wrap's High-level API, you will see examples of sub-classes of <gw-type> dedicated to wrapping certain C types, such as pointers, integers, strings, etc.

Besides C code generation methods, a number of methods apply to all instances of <gw-type>. Code generation methods are described separately, in section See G-Wrap's Code Generation API.

method: name (type <gw-type>)

Return a symbol denoting the Scheme name for wrapped type type.

method: class-name (type <gw-type>)


method: needs-result-var? (type <gw-type>)


method: arguments-visible? (type <gw-type>)


method: default-c-value-for-type (type <gw-type>)

On success, return a string that represents some default C value for type (e.g., "NULL" if type is a pointer type). This is useful, for instance, to generate C code where no variable is left uninitialized. If no default C value is known for type, then #f is returned.

Wrapped C types in G-Wrap are broadly separated into two classes: those for which information is available at run-time, and those for which this is not the case. Run-time type information (or RTTI, or RTI, whichever you prefer) allows G-Wrap’s support run-time libraries to manipulate C objects whose type they only know at run-time. In particular, this allows those libraries to construct C function calls at run-time, instead of letting generated code do this (see Wrapped Functions).

Wrapped types for which information is available at run-time are represented by the <gw-rti-type> class (a sub-class of <gw-type>), defined in (g-wrap rti). Actually, most of the C types wrapped by G-Wrap’s standard wrapset (see C Types Provided in the Standard Wrapset) are sub-classes of this class. Ranged integers, wrapped C pointers (see Wrapping a C Pointer Type), strings, are RTI types. Even user-defined so-called simple types (see see Wrapping Another Simple C Type) inherit from <gw-rti-type>: all the user needs to do is pass the appropriate run-time type specification, via the #:ffspec option.

A number of additional methods are defined for instances of <gw-rti-type>:

method: allowed-options (type <gw-rti-type>)


method: c-type-name (type <gw-rti-type>)

Return a string representing the name of the C type wrapped by type.

method: c-const-type-name (type <gw-rti-type>)

Return a string representing the const-qualified version of the C type wrapped by type.

method: ffspec (type <gw-rti-type>)

Return a symbol denoting run-time type information for the C type wrapped by type. This symbol corresponds to a type tag understandable by libffi (see Wrapping Another Simple C Type).

method: wrap-value-function-name (type <gw-rti-type>)
method: unwrap-value-function-name (type <gw-rti-type>)
method: destroy-value-function-name (type <gw-rti-type>)

Return a string denoting the name of the C function that wraps, unwraps, or destroys instances of the C type wrapped by type (see See Wrapping Another Simple C Type, for details).

Next: , Previous: , Up: Basic Concepts   [Contents][Index]