Next: Smobs, Previous: Data Types, Up: API Reference [Contents][Index]
This chapter contains reference information related to defining and working with foreign objects. See Defining New Foreign Object Types, for a tutorial-like introduction to foreign objects.
This function type returns void
and takes one SCM
argument.
Create a fresh foreign object type. name is a symbol naming the
type. slots is a list of symbols, each one naming a field in the
foreign object type. finalizer indicates the finalizer, and may
be NULL
.
We recommend that finalizers be avoided if possible. See Foreign Object Memory Management. Finalizers must be async-safe and
thread-safe. Again, see Foreign Object Memory Management. If you
are embedding Guile in an application that is not thread-safe, and you
define foreign object types that need finalization, you might want to
disable automatic finalization, and arrange to call
scm_manually_run_finalizers ()
yourself.
Enable or disable automatic finalization. By default, Guile arranges to
invoke object finalizers automatically, in a separate thread if
possible. Passing a zero value for enabled_p will disable
automatic finalization for Guile as a whole. If you disable automatic
finalization, you will have to call scm_run_finalizers ()
periodically.
Unlike most other Guile functions, you can call
scm_set_automatic_finalization_enabled
before Guile has been
initialized.
Return the previous status of automatic finalization.
Invoke any pending finalizers. Returns the number of finalizers that were invoked. This function should be called when automatic finalization is disabled, though it may be called if it is enabled as well.
When val is a foreign object of the given type, do nothing. Otherwise, signal an error.
Make a new foreign object of the type with type type and initialize the first n fields to the given values, as appropriate.
The number of fields for objects of a given type is fixed when the type is created. It is an error to give more initializers than there are fields in the value. It is perfectly fine to give fewer initializers than needed; this is convenient when some fields are of non-pointer types, and would be easier to initialize with the setters described below.
Return the value of the nth field of the foreign object obj.
The backing store for the fields is as wide as a scm_t_bits
value, which is at least as wide as a pointer. The different variants
handle casting in a portable way.
Set the value of the nth field of the foreign object obj to
val, after portably converting to a scm_t_bits
value, if
needed.
One can also access foreign objects from Scheme. See Foreign Objects and Scheme, for some examples.
(use-modules (system foreign-object))
Make a new foreign object type. See the above documentation for
scm_make_foreign_object_type
; these functions are exactly
equivalent, except for the way in which the finalizer gets attached to
instances (an internal detail).
The resulting value is a GOOPS class. See GOOPS, for more on classes in Guile.
A convenience macro to define a type, using
make-foreign-object-type
, and bind it to name. A
constructor will be bound to constructor, and getters will be
bound to each of slot....
Next: Smobs, Previous: Data Types, Up: API Reference [Contents][Index]