2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2002--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "lily-guile.hh"
21 #include "ly-module.hh"
24 #include "protected-scm.hh"
25 #include "lily-imports.hh"
28 ly_make_module (bool safe)
33 /* Look up (evaluate) Scheme make-module function and call it */
35 mod = Guile_user::make_module ();
37 Look up and call Guile module-export-all! or, when using
38 Guile V1.8, the compatible shim defined in lily.scm.
41 Guile_user::module_export_all_x (mod);
43 Lily::module_export_all_x (mod);
47 Evaluate Guile module "the-root-module",
48 and ensure we inherit definitions from it and the "lily" module
49 N.B. this used to be "the-scm-module" and is deprecated in
53 ly_use_module (mod, Guile_user::the_root_module);
54 ly_use_module (mod, Lily::module);
58 /* Evaluate and call make-safe-lilypond-module */
59 mod = Lily::make_safe_lilypond_module ();
66 ly_use_module (SCM mod, SCM used)
69 Pick up the module's interface definition.
70 TODO - Replace inline evaluations (interpreted)
71 with guile API calls if these become available.
75 '(module_use! <mod> (module-public-interface <used>))'
77 return Guile_user::module_use_x (mod,
78 Guile_user::module_public_interface (used));
81 #define FUNC_NAME __FUNCTION__
84 ly_module_symbols (SCM mod)
86 SCM_VALIDATE_MODULE (1, mod);
88 SCM obarr = SCM_MODULE_OBARRAY (mod);
89 return ly_hash_table_keys (obarr);
93 entry_to_alist (void * /* closure */,
98 if (to_boolean (scm_variable_bound_p (val)))
99 return scm_cons (scm_cons (key, scm_variable_ref (val)), result);
100 programming_error ("unbound variable in module");
104 LY_DEFINE (ly_module_2_alist, "ly:module->alist",
106 "Dump the contents of module @var{mod} as an alist.")
108 SCM_VALIDATE_MODULE (1, mod);
109 SCM obarr = SCM_MODULE_OBARRAY (mod);
111 return scm_internal_hash_fold ((scm_t_hash_fold_fn) &entry_to_alist,
112 NULL, SCM_EOL, obarr);
116 ly_export (SCM module, SCM namelist)
118 Guile_user::module_export_x (module, namelist);
122 ly_reexport_module (SCM mod)
124 ly_export (mod, ly_module_symbols (mod));