Adding a new type
=================
- Function: add-type scheme-sym c-name fn-to-scm fn-from-scm fn-isa
Defines a new Scheme type corresponding to C-type C-NAME, and
associates it with symbol SCHEME-SYM. Objects of this type are
printed with C-function C-PRINT-NAME, deallocated by C-function
C-DIE-NAME, and checked for equality with C-function C-EQ-NAME.
Scheme-sym should be a symbol, and the other arguments should be
strings.
- Function: new-type scheme-sym c-name c-print-fn c-die-fn c-eq-fn
[options ...]
As does `add-type', this command defines a new Scheme type
corresponding to C-type C-NAME, and associates it with symbol
SCHEME-SYM. SCHEME-SYM can then be used as a type parameter in
functions `new-constant' and `new-function'. In addition, a
function called C-NAME? is generated to test if any Scheme object
is an object of this type.
`new-type' also documents the type in documentation file. If
`(doc DESCRIPTION)' is passed as an option, DESCRIPTION is used
to document the type.
Example:
(new-type 'MAT "MAT" "MAT_print" "m_free" "MAT_eq")
* A Scheme function `MAT?' is defined to test to see if a
Scheme value has this type.
* C functions must be provided for performing the tasks of
performing the basic jobs which the interpreter needs to
perform for Scheme objects. In this example, `MAT_print'
writes the representation of the matrix to a port, `MAT_die'
deallocates the matrix, `MAT_eq' checks for equality of
matrices. See Note:C code needed for adding new types to
see how to write these functions.
* This allows `MAT's to be used as function parameters and as
return values.
* For Guile, this creates a new smob type for holding (`MAT*')
pointers, and for RScheme it creates a new object-class for
the type.