]> git.donarmstrong.com Git - lilypond.git/blob - lily/music-function-scheme.cc
Web-ja: update introduction
[lilypond.git] / lily / music-function-scheme.cc
1 #include "music-function.hh"
2
3 LY_DEFINE (ly_music_function_extract, "ly:music-function-extract", 1, 0, 0,
4            (SCM x),
5            "Return the Scheme function inside@tie{}@var{x}.")
6 {
7   LY_ASSERT_SMOB (Music_function, x, 1);
8
9   return unsmob<Music_function> (x)->get_function ();
10 }
11
12 LY_DEFINE (ly_music_function_signature, "ly:music-function-signature", 1, 0, 0,
13            (SCM x),
14            "Return the function signature inside@tie{}@var{x}.")
15 {
16   LY_ASSERT_SMOB (Music_function, x, 1);
17
18   return unsmob<Music_function> (x)->get_signature ();
19 }
20
21 LY_DEFINE (ly_make_music_function, "ly:make-music-function", 2, 0, 0,
22            (SCM signature, SCM func),
23            "Make a function to process music, to be used for the"
24            " parser.  @var{func} is the function, and @var{signature}"
25            " describes its arguments.  @var{signature}'s cdr is a list"
26            " containing either @code{ly:music?} predicates or other type"
27            " predicates.  Its car is the syntax function to call.")
28 {
29   LY_ASSERT_TYPE (ly_is_list, signature, 1);
30   LY_ASSERT_TYPE (ly_is_procedure, func, 2);
31   int n = 0;
32   for (SCM p = signature; scm_is_pair (p); p = scm_cdr (p), ++n)
33     {
34       SCM proc = scm_car (p);
35       if (scm_is_pair (proc))
36         proc = scm_car (proc);
37       if (scm_is_false (scm_procedure_p (proc)))
38         {
39           scm_wrong_type_arg_msg ("music-function", n, p,
40                                   "music function predicate");
41         }
42     }
43
44   return Music_function::make_smob (signature, func);
45 }