Previous: C Types Provided in the Standard Wrapset, Up: G-Wrap's High-level API [Contents][Index]
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:
#:name
a symbol that is the name for this wrapped type as used within the G-Wrap framework;
#:c-type-name
a string that is the C name of this enumerate type;
#:type-check
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-var
symbol which will be
expanded to the name of the C variable that holds the Scheme value;
#:ffspec
a symbol representing the libffi type name that describes this type
best; it may be, for instance, pointer
for pointer types,
long
for long integers, etc.; in other words, this is meant to
provide run-time type information, as described in See Wrapped Types.
#:unwrap
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-var
will be
expanded to the name of the C variable that holds the Scheme value,
while the symbol c-var
will be expanded to the C variables that
will hold the corresponding C value;
#:wrap
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 #:unwrap
;
#:description
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 Guile’s SCM type in The GNU Guile
Reference Manual) 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"))
Note that the scm
type is part of the standard wrapset
(see C Types Provided in the Standard Wrapset).
If 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.
Previous: C Types Provided in the Standard Wrapset, Up: G-Wrap's High-level API [Contents][Index]