]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/music-function-scheme.cc
Web-ja: update introduction
[lilypond.git] / lily / music-function-scheme.cc
index f78a387336021f9c1166aec680b9fb1cae610e5c..5246b6dbe6282c3dc0e67e41c74611d3a49e9d5c 100644 (file)
@@ -1,30 +1,45 @@
 #include "music-function.hh"
 
-LY_DEFINE (ly_music_function_p, "ly:music-function?", 1, 0, 0,
+LY_DEFINE (ly_music_function_extract, "ly:music-function-extract", 1, 0, 0,
            (SCM x),
-           "Is @var{x} a @code{music-function}?")
+           "Return the Scheme function inside@tie{}@var{x}.")
 {
-  return is_music_function (x) ? SCM_BOOL_T : SCM_BOOL_F;
+  LY_ASSERT_SMOB (Music_function, x, 1);
+
+  return unsmob<Music_function> (x)->get_function ();
 }
 
-LY_DEFINE (ly_music_function_extract, "ly:music-function-extract", 1, 0, 0,
+LY_DEFINE (ly_music_function_signature, "ly:music-function-signature", 1, 0, 0,
            (SCM x),
-           "Return the Scheme function inside@tie{}@var{x}.")
+           "Return the function signature inside@tie{}@var{x}.")
 {
-  LY_ASSERT_TYPE (is_music_function, x, 1);
+  LY_ASSERT_SMOB (Music_function, x, 1);
 
-  return SCM_CELL_OBJECT_1 (x);
+  return unsmob<Music_function> (x)->get_signature ();
 }
 
 LY_DEFINE (ly_make_music_function, "ly:make-music-function", 2, 0, 0,
            (SCM signature, SCM func),
            "Make a function to process music, to be used for the"
            " parser.  @var{func} is the function, and @var{signature}"
-           " describes its arguments.  @var{signature} is a list"
+           " describes its arguments.  @var{signature}'s cdr is a list"
            " containing either @code{ly:music?} predicates or other type"
-           " predicates.")
+           " predicates.  Its car is the syntax function to call.")
 {
-  LY_ASSERT_TYPE (ly_is_procedure, func, 1);
-  return make_music_function (signature, func);
-}
+  LY_ASSERT_TYPE (ly_is_list, signature, 1);
+  LY_ASSERT_TYPE (ly_is_procedure, func, 2);
+  int n = 0;
+  for (SCM p = signature; scm_is_pair (p); p = scm_cdr (p), ++n)
+    {
+      SCM proc = scm_car (p);
+      if (scm_is_pair (proc))
+        proc = scm_car (proc);
+      if (scm_is_false (scm_procedure_p (proc)))
+        {
+          scm_wrong_type_arg_msg ("music-function", n, p,
+                                  "music function predicate");
+        }
+    }
 
+  return Music_function::make_smob (signature, func);
+}