]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/module-scheme.cc
Issue 5167/6: Changes: show \markup xxx = ... \etc assignments
[lilypond.git] / lily / module-scheme.cc
index bcea57a6fd719ca9f9fe82f859d1c171201752be..eda467fe68b259336663f08ccfaf72f1e2818afb 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 2005--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
   LilyPond is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -17,8 +17,7 @@
   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "ly-module.hh"
-
+#include "ly-module.hh" // pulls in lily-guile.hh and guile-compatibility.hh
 #include "warn.hh"
 #include "main.hh"
 #include "std-string.hh"
@@ -34,8 +33,8 @@ module_define_closure_func (void *closure,
                             SCM val,
                             SCM /* result */)
 {
-  SCM module = (SCM) closure;
-  if (scm_variable_bound_p (val) == SCM_BOOL_T)
+  SCM module = *static_cast<SCM *> (closure);
+  if (to_boolean (scm_variable_bound_p (val)))
     scm_module_define (module, key, scm_variable_ref (val));
   return SCM_EOL;
 }
@@ -47,19 +46,36 @@ LY_DEFINE (ly_module_copy, "ly:module-copy",
 #define FUNC_NAME __FUNCTION__
   SCM_VALIDATE_MODULE (1, src);
   scm_internal_hash_fold ((scm_t_hash_fold_fn) &module_define_closure_func,
-                          (void *) dest,
+                          static_cast<void *> (&dest),
                           SCM_EOL, SCM_MODULE_OBARRAY (src));
   return SCM_UNSPECIFIED;
 }
 
-/* Lookup SYM, but don't give error when it is not defined.  */
+
+
+/* Lookup SYM, but don't give error when it is not defined.
+   N.B. this is only needed when running with Guile versions
+   prior to V2.0.3, when calls to ly_module_lookup can be replaced
+   with direct calls to the Guile API scm_module_variable in the
+   LilyPond codebase.
+*/
 SCM
 ly_module_lookup (SCM module, SCM sym)
 {
 #define FUNC_NAME __FUNCTION__
   SCM_VALIDATE_MODULE (1, module);
-
+/*
+  Issue 2758:
+    Guile V2 onward has a scm_module_variable API module.
+    Guile V1.8.7 only has a (module-variable) REPL function and we
+    can't import this via Scm_variable since that needs
+    ly_module_lookup itself.
+ */
+#if GUILEV1
   return scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F);
+#else
+  return scm_module_variable (module, sym);
+#endif
 #undef FUNC_NAME
 }
 
@@ -76,11 +92,11 @@ LY_DEFINE (ly_modules_lookup, "ly:modules-lookup",
     {
       SCM mod = scm_car (s);
       SCM v = ly_module_lookup (mod, sym);
-      if (SCM_VARIABLEP (v) && SCM_VARIABLE_REF (v) != SCM_UNDEFINED)
+      if (SCM_VARIABLEP (v) && !SCM_UNBNDP (SCM_VARIABLE_REF (v)))
         return scm_variable_ref (v);
     }
 
-  if (def != SCM_UNDEFINED)
+  if (!SCM_UNBNDP (def))
     return def;
   return SCM_BOOL_F;
 }