]> git.donarmstrong.com Git - lilypond.git/blob - lily/identifier-smob.cc
Imported Upstream version 2.14.2
[lilypond.git] / lily / identifier-smob.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2002--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "identifier-smob.hh"
21
22 scm_t_bits package_tag;
23
24 static int
25 print_box (SCM b, SCM port, scm_print_state *)
26 {
27   SCM value = SCM_CELL_OBJECT_1 (b);
28
29   scm_puts ("#<packaged object ", port);
30   scm_write (value, port);
31   scm_puts (">", port);
32
33   /* Non-zero means success.  */
34   return 1;
35 }
36
37 /* This defines the primitve `make-box', which returns a new smob of
38    type `box', initialized to `#f'.  */
39 LY_DEFINE (ly_export, "ly:export",
40            1, 0, 0, (SCM arg),
41            "Export a Scheme object to the parser"
42            " so it is treated as an identifier.")
43 {
44   SCM_RETURN_NEWSMOB (package_tag, arg);
45 }
46
47 SCM
48 unpack_identifier (SCM box)
49 {
50   if (SCM_IMP (box) || SCM_CELL_TYPE (box) != package_tag)
51     return SCM_UNDEFINED;
52
53   return SCM_CELL_OBJECT_1 (box);
54 }
55
56 static void
57 init_box_type (void)
58 {
59   package_tag = scm_make_smob_type ("box", 0);
60   scm_set_smob_mark (package_tag, scm_markcdr);
61   scm_set_smob_print (package_tag, print_box);
62 }
63
64 ADD_SCM_INIT_FUNC (package, init_box_type);