[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#31154: predicate function for foreign-object not obvious
From: |
Matt Wette |
Subject: |
bug#31154: predicate function for foreign-object not obvious |
Date: |
Sat, 14 Apr 2018 11:33:59 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 |
The reference manual (guile-2.2.3) does not provide instruction on how to
generate
a predicate for a foreign object, and it is not obvious. Maybe it doesn't need
to
be in the manual but should then be in an example somewhere, IMO.
The following patch to the reference manual is one option:
--- doc/ref/api-foreign-objects.texi-orig 2018-04-14 11:26:35.779502997
-0700
+++ doc/ref/api-foreign-objects.texi 2018-04-14 11:28:42.823072217 -0700
@@ -96,6 +96,33 @@
needed.
@end deftypefn
+To generate a predicate for a foreign object use the @code{SCM_IS_A_P}
+macro as follows.
+
address@hidden
+static SCM foo_type;
+
+static SCM
+scm_foo_p(SCM obj) {
+ return SCM_IS_A_P(obj, foo_type)? SCM_BOOL_T: SCM_BOOL_F;
+}
+
+void
+init_foo()
+{
+ SCM name, slots;
+
+ name = scm_from_utf8_symbol("foo");
+ slots = scm_list_2 (scm_from_utf8_symbol ("data"),
+ scm_from_utf8_symbol ("deps"));
+ finalizer = NULL;
+ foo_type = scm_make_foreign_object_type(name, slots, finalizer);
+
+ scm_c_define_gsubr("foo?", 1, 0, 0, scm_foo_p);
+ ...
+}
address@hidden example
+
One can also access foreign objects from Scheme. @xref{Foreign Objects
and Scheme}, for some examples.
- bug#31154: predicate function for foreign-object not obvious,
Matt Wette <=