]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-array-scheme.cc
Web-ja: update introduction
[lilypond.git] / lily / grob-array-scheme.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "grob-array.hh"
22 #include "grob.hh"
23
24 LY_DEFINE (ly_grob_array_length, "ly:grob-array-length",
25            1, 0, 0,
26            (SCM grob_arr),
27            "Return the length of @var{grob-arr}.")
28 {
29   LY_ASSERT_SMOB (Grob_array, grob_arr, 1);
30
31   Grob_array *me = unsmob<Grob_array> (grob_arr);
32   return scm_from_int (me->size ());
33 }
34
35 LY_DEFINE (ly_grob_array_ref, "ly:grob-array-ref",
36            2, 0, 0,
37            (SCM grob_arr, SCM index),
38            "Retrieve the @var{index}th element of @var{grob-arr}.")
39 {
40   Grob_array *me = unsmob<Grob_array> (grob_arr);
41   LY_ASSERT_SMOB (Grob_array, grob_arr, 1);
42   LY_ASSERT_TYPE (scm_is_integer, index, 2);
43
44   vsize i = scm_to_uint (index);
45   if (i == VPOS || i >= me->size ())
46     scm_out_of_range (NULL, scm_from_unsigned_integer (i));
47
48   return me->grob (i)->self_scm ();
49 }
50
51 LY_DEFINE (ly_grob_array_2_list, "ly:grob-array->list",
52            1, 0, 0,
53            (SCM grob_arr),
54            "Return the elements of @var{grob-arr} as a Scheme list.")
55 {
56   Grob_array *me = unsmob<Grob_array> (grob_arr);
57   LY_ASSERT_SMOB (Grob_array, grob_arr, 1);
58
59   return grob_array_to_list (me);
60 }