If you want to wrap a simple C type which is does not fit in any of the categories above, then G-Wrap provides a simple high-level function for that purpose.
Add the type described by args to the list of types to be wrapped by wrapset. The arguments in args must contain the following named parameters:
- a symbol that is the name for this wrapped type as used within the G-Wrap framework;
- a string that is the C name of this enumerate type;
- a list representing C expression that returns true if the given Scheme value's type is this type; this list may contain strings (representing part of the C expression) and the
scm-varsymbol which will be expanded to the name of the C variable that holds the Scheme value;
- a symbol representing the libffi type name that describes this type best; it may be, for instance,
pointerfor pointer types,
longfor long integers, etc.; in other words, this is meant to provide run-time type information, as described in See Wrapped Types.
- a list representing a C statement that assigns (and converts) the value of a C variable holding a Scheme value to a C variable holding the corresponding C value; as for
#:type-check, this list may only contain strings and symbols; the symbol
scm-varwill be expanded to the name of the C variable that holds the Scheme value, while the symbol
c-varwill be expanded to the C variables that will hold the corresponding C value;
- a list representing a C statement that assigns (and converts) the value of a C variable holding a C value to a C variable holding the corresponding Scheme value; the content and interpretation of the list as the same as for
- an optional description of this type.
As an example, the simple
scm wrapped type which lets the user
wrap C functions that take or return raw
SCM objects (see
see Guile's SCM type, for a description of
Guile's C type for Scheme objects) is defined as follows:
(wrap-simple-type! wrapset #:name 'scm #:c-type-name "SCM" #:type-check '("1") ;; any Scheme value is correct #:ffspec 'pointer ;; no conversion is needed #:unwrap '(c-var " = " scm-var ";\n") #:wrap '(scm-var " = " c-var ";\n"))
wrap-simple-type! is still not good enough for what you want
to do, then you may have a look at the details of G-Wrap's code
generation interface, See G-Wrap's Code Generation API.