aboutsummaryrefslogtreecommitdiffstats
path: root/modules/opaque/opaque.c
diff options
context:
space:
mode:
Diffstat (limited to 'modules/opaque/opaque.c')
-rw-r--r--modules/opaque/opaque.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/modules/opaque/opaque.c b/modules/opaque/opaque.c
new file mode 100644
index 00000000000..2366b2ed2e9
--- /dev/null
+++ b/modules/opaque/opaque.c
@@ -0,0 +1,64 @@
1#include <config.h>
2#include <lisp.h>
3
4int plugin_is_GPL_compatible;
5static Lisp_Object Qopaque;
6
7struct opaque
8{
9 int a, b, c;
10};
11
12static Lisp_Object Qa, Qb, Qc;
13
14EXFUN (Fopaque_make, 3);
15DEFUN ("opaque-make", Fopaque_make, Sopaque_make, 3, 3, 0,
16 doc: "Make opaque type.")
17 (Lisp_Object a, Lisp_Object b, Lisp_Object c)
18{
19 struct opaque *p = malloc (sizeof (*p));
20 p->a = XINT (a);
21 p->b = XINT (b);
22 p->c = XINT (c);
23
24 /*
25 store p as a the first slot (index 0) of a Lisp_Save_Value (which
26 is a Lisp_Misc)
27 */
28 return make_save_ptr ((void*)p);
29}
30
31EXFUN (Fopaque_free, 1);
32DEFUN ("opaque-free", Fopaque_free, Sopaque_free, 1, 1, 0,
33 doc: "Free opaque object OBJ.")
34 (Lisp_Object obj)
35{
36 /* the pointer is in the first slot (index 0) */
37 free (XSAVE_POINTER (obj, 0));
38 return Qnil;
39}
40
41EXFUN (Fopaque_get, 2);
42DEFUN ("opaque-get", Fopaque_get, Sopaque_get, 2, 2, 0,
43 doc: "Return the field F (`a', `b', `c') of the opaque object OBJ.")
44 (Lisp_Object obj, Lisp_Object f)
45{
46 struct opaque *p = XSAVE_POINTER (obj, 0);
47 int val = EQ (f, Qa) ? p->a : EQ (f, Qb) ? p->b : EQ (f, Qc) ? p->c : -1;
48 return make_number (val);
49}
50
51void init ()
52{
53 DEFSYM (Qopaque, "opaque");
54
55 DEFSYM (Qa, "a");
56 DEFSYM (Qb, "b");
57 DEFSYM (Qc, "c");
58
59 defsubr (&Sopaque_make);
60 defsubr (&Sopaque_free);
61 defsubr (&Sopaque_get);
62
63 Fprovide (Qopaque, Qnil);
64}