emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] dynamic-modules 1be7b68 10/22: new module: opaque


From: Noah Friedman
Subject: [Emacs-diffs] dynamic-modules 1be7b68 10/22: new module: opaque
Date: Mon, 8 May 2017 19:46:13 -0400 (EDT)

branch: dynamic-modules
commit 1be7b68e1260220f256131a239f1be535269f33c
Author: Aurélien Aptel <address@hidden>
Commit: Ted Zlatanov <address@hidden>

    new module: opaque
    
    The opaque module is a simple module which shows how to embed any C
    type in a Lisp_Object.
---
 modules/opaque/Makefile | 12 +++++++++++
 modules/opaque/opaque.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)

diff --git a/modules/opaque/Makefile b/modules/opaque/Makefile
new file mode 100644
index 0000000..7f50732
--- /dev/null
+++ b/modules/opaque/Makefile
@@ -0,0 +1,12 @@
+ROOT = ../..
+
+all: opaque.so opaque.doc
+
+%.so: %.o
+       gcc -shared -o $@ $<
+
+%.o: %.c
+       gcc -ggdb3 -Wall -I$(ROOT)/src -I$(ROOT)/lib -fPIC -c $<
+
+%.doc: %.c
+       $(ROOT)/lib-src/make-docfile $< > $@
diff --git a/modules/opaque/opaque.c b/modules/opaque/opaque.c
new file mode 100644
index 0000000..f1ba759
--- /dev/null
+++ b/modules/opaque/opaque.c
@@ -0,0 +1,53 @@
+#include <config.h>
+#include <lisp.h>
+
+int plugin_is_GPL_compatible;
+
+struct opaque
+{
+  int a, b, c;
+};
+
+static Lisp_Object Qa, Qb, Qc;
+
+EXFUN (Fopaque_make, 3);
+DEFUN ("opaque-make", Fopaque_make, Sopaque_make, 3, 3, 0,
+       doc: "Make opaque type.")
+  (Lisp_Object a, Lisp_Object b, Lisp_Object c)
+{
+  struct opaque *p = malloc (sizeof (*p));
+  p->a = XINT (a);
+  p->b = XINT (b);
+  p->c = XINT (c);
+  return make_save_ptr ((void*)p);
+}
+
+EXFUN (Fopaque_free, 1);
+DEFUN ("opaque-free", Fopaque_free, Sopaque_free, 1, 1, 0,
+       doc: "Free opaque type.")
+  (Lisp_Object p)
+{
+  free (XSAVE_POINTER (p, 0));
+  return Qnil;
+}
+
+EXFUN (Fopaque_get, 2);
+DEFUN ("opaque-get", Fopaque_get, Sopaque_get, 2, 2, 0,
+       doc: "Return the field F (`a', `b', `c') of the opaque object OBJ.")
+  (Lisp_Object obj, Lisp_Object f)
+{
+  struct opaque *p = XSAVE_POINTER (obj, 0);
+  int val = EQ (f, Qa) ? p->a : EQ (f, Qb) ? p->b : EQ (f, Qc) ? p->c : -1;
+  return make_number (val);
+}
+
+void init ()
+{
+  DEFSYM (Qa, "a");
+  DEFSYM (Qb, "b");
+  DEFSYM (Qc, "c");
+
+  defsubr (&Sopaque_make);
+  defsubr (&Sopaque_free);
+  defsubr (&Sopaque_get);
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]