]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier-smob.cc
2003 -> 2004
[lilypond.git] / lily / identifier-smob.cc
1 /*   
2 identifier-smob.cc -- implement glue to pass Scheme expressions off as
3 identifiers.
4
5 source file of the GNU LilyPond music typesetter
6
7 (c) 2002--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8
9 */
10 #include "identifier-smob.hh"
11 /*
12   C&P from example/box.c
13  */
14
15 scm_t_bits package_tag;
16
17 /* Print a textual represenation of the smob to a given port.  */
18 static int
19 print_box (SCM b, SCM port, scm_print_state *pstate)
20 {
21   SCM value = SCM_CELL_OBJECT_1 (b);
22
23   scm_puts ("#<packaged object ", port);
24   scm_write (value, port);
25   scm_puts (">", port);
26
27   /* Non-zero means success.  */
28   return 1;
29 }
30
31
32 /* This defines the primitve `make-box', which returns a new smob of
33    type `box', initialized to `#f'.  */
34 LY_DEFINE(package_identifier, "ly:export", 1,0,0, (SCM arg),
35           "Export a Scheme object to the parser, so it is treated as an identifier.")
36 {
37   /* This macro creates the new objects, stores the value `#f' into it
38      and returns it to the caller.  */
39   SCM_RETURN_NEWSMOB (package_tag, arg);
40 }
41
42
43 /* This is the primitive `box-ref' which returns the object stored in
44    the box.  */
45 SCM
46 unpack_identifier(SCM box)
47 {
48   if (SCM_IMP(box) || SCM_CELL_TYPE(box) != package_tag)
49     return SCM_UNDEFINED;
50   
51   return SCM_CELL_OBJECT_1 (box);
52 }
53
54 static void
55 init_box_type (void)
56 {
57   package_tag = scm_make_smob_type ("box", 0);
58   scm_set_smob_mark (package_tag, scm_markcdr);
59   scm_set_smob_print (package_tag, print_box);
60 }
61 ADD_SCM_INIT_FUNC(package, init_box_type);