lilypond-1.1.9
[lilypond.git] / lily / lily-guile.cc
blob8599b9ba9569e55dfe2718fcf778a98a3b8ea0ac
1 /*
2 lily-guile.cc -- implement assorted guile functions
4 source file of the GNU LilyPond music typesetter
6 (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
8 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 */
11 #include <stdio.h>
12 #include "libc-extension.hh"
13 #include "lily-guile.hh"
14 #include "main.hh"
15 #include "simple-file-storage.hh"
16 #include "file-path.hh"
18 SCM
19 ly_list1 (SCM a)
21 return gh_list (a, SCM_UNDEFINED);
24 SCM
25 ly_quote ()
27 return gh_eval_str ("'quote");
31 scm_m_quote doesn't use any env, but needs one for a good signature in GUILE.
33 Why there is no gh_quote () in GUILE beats me.
36 SCM
37 ly_quote_scm (SCM s)
39 // return scm_m_quote (s, SCM_UNDEFINED);
40 return scm_cons2 (scm_i_quote, s, SCM_EOL);
44 SCM
45 ly_eval (SCM a)
47 return gh_call1 (gh_eval_str ("eval"), a);
50 SCM
51 ly_lambda_o ()
53 return gh_eval_str ("'(lambda (o))");
56 SCM
57 ly_func_o (char const* name)
59 char buf[200]; // ugh.
60 snprintf (buf, 200, "'(%s o)", name);
61 return gh_eval_str (buf);
65 SCM
66 lambda_scm (String str, Array<int> args_arr)
68 if (str.empty_b ())
70 str = "empty";
71 args_arr.clear ();
73 SCM args_scm = SCM_EOL;
74 for (int i = args_arr.size () - 1; i >= 0; i--)
75 args_scm = gh_cons (gh_int2scm (args_arr[i]), args_scm);
76 SCM scm =
77 gh_append2 (ly_lambda_o (),
78 ly_list1 (gh_append2 (ly_func_o (str.ch_l ()), args_scm)));
79 return scm;
82 // scm_top_level_env(SCM_CDR(scm_top_level_lookup_closure_var)))
83 SCM
84 lambda_scm (String str, Array<Scalar> args_arr)
86 if (str.empty_b ())
88 str = "empty";
89 args_arr.clear ();
91 SCM args_scm = SCM_EOL;
92 for (int i = args_arr.size (); i--; )
93 args_scm = gh_cons (gh_str02scm (args_arr[i].ch_l ()), args_scm);
94 SCM scm =
95 gh_append2 (ly_lambda_o (),
96 ly_list1 (gh_append2 (ly_func_o (str.ch_l ()), args_scm)));
97 return scm;
101 lambda_scm (String str, Array<Real> args_arr)
103 if (str.empty_b ())
105 str = "empty";
106 args_arr.clear ();
108 SCM args_scm = SCM_EOL;
109 for (int i = args_arr.size (); i--; )
110 args_scm = gh_cons (gh_double2scm (args_arr[i]), args_scm);
112 SCM scm =
113 gh_append2 (ly_lambda_o (),
114 ly_list1 (gh_append2 (ly_func_o (str.ch_l ()), args_scm)));
115 return scm;
120 Read a file, and shove it down GUILE. GUILE also has file read
121 functions, but you can't fiddle with the path of those.
125 void
126 read_lily_scm_file (String fn)
128 String s = global_path.find (fn);
129 Simple_file_storage f(s);
131 gh_eval_str ((char *) f.ch_C());