unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#31154: predicate function for foreign-object not obvious
@ 2018-04-14 18:33 Matt Wette
       [not found] ` <handler.31154.B.152373085729032.ack@debbugs.gnu.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Matt Wette @ 2018-04-14 18:33 UTC (permalink / raw)
  To: 31154

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.
+
+@example
+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);
+  ...
+}
+@end example
+
  One can also access foreign objects from Scheme.  @xref{Foreign Objects
  and Scheme}, for some examples.
  






^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#31154: Acknowledgement (predicate function for foreign-object not obvious)
       [not found] ` <handler.31154.B.152373085729032.ack@debbugs.gnu.org>
@ 2018-04-14 19:25   ` Matt Wette
  0 siblings, 0 replies; 2+ messages in thread
From: Matt Wette @ 2018-04-14 19:25 UTC (permalink / raw)
  To: 31154

Perhaps it belongs with the demo in Section 5.5 Defining New Foreign Object Types,
with the image demo.






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-14 19:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-14 18:33 bug#31154: predicate function for foreign-object not obvious Matt Wette
     [not found] ` <handler.31154.B.152373085729032.ack@debbugs.gnu.org>
2018-04-14 19:25   ` bug#31154: Acknowledgement (predicate function for foreign-object not obvious) Matt Wette

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).