* strports.h (scm_c_eval_string_in_module,
authorMarius Vollmer <mvo@zagadka.de>
Tue, 13 Aug 2002 20:54:12 +0000 (20:54 +0000)
committerMarius Vollmer <mvo@zagadka.de>
Tue, 13 Aug 2002 20:54:12 +0000 (20:54 +0000)
scm_eval_string_in_module): New prototypes.
* strports.c (scm_eval_string_in_module): New, but use
"eval-string" as the Scheme name and make second parameter
optional.
(scm_eval_string): Implement using scm_eval_string_in_module.
(scm_c_eval_string_in_module): New.
Thanks to Ralf Mattes for the suggestion!

libguile/strports.c
libguile/strports.h

index 5af68bb..44a8db5 100644 (file)
@@ -440,6 +440,13 @@ scm_c_eval_string (const char *expr)
   return scm_eval_string (scm_makfrom0str (expr));
 }
 
+SCM
+scm_c_eval_string_in_module (const char *expr, SCM module)
+{
+  return scm_eval_string_in_module (scm_makfrom0str (expr), module);
+}
+
+
 static SCM
 inner_eval_string (void *data)
 {
@@ -459,21 +466,32 @@ inner_eval_string (void *data)
   return ans;
 }
 
-SCM_DEFINE (scm_eval_string, "eval-string", 1, 0, 0, 
-            (SCM string),
+SCM_DEFINE (scm_eval_string_in_module, "eval-string", 1, 1, 0, 
+            (SCM string, SCM module),
            "Evaluate @var{string} as the text representation of a Scheme\n"
            "form or forms, and return whatever value they produce.\n"
-           "Evaluation takes place in the environment returned by the\n"
-           "procedure @code{interaction-environment}.")
-#define FUNC_NAME s_scm_eval_string
+           "Evaluation takes place in the given module, or the current\n"
+            "module when no module is given.\n"
+            "While the code is evaluated, the given module is made the\n"
+           "current one.  The current module is restored when this\n"
+            "procedure returns.")
+#define FUNC_NAME s_scm_eval_string_in_module
 {
   SCM port = scm_mkstrport (SCM_INUM0, string, SCM_OPN | SCM_RDNG,
-                           "eval-string");
-  return scm_c_call_with_current_module (scm_interaction_environment (),
+                           FUNC_NAME);
+  if (SCM_UNBNDP (module))
+    module = scm_current_module ();
+  return scm_c_call_with_current_module (module,
                                         inner_eval_string, (void *)port);
 }
 #undef FUNC_NAME
 
+SCM
+scm_eval_string (SCM string)
+{
+  return scm_eval_string_in_module (string, SCM_UNDEFINED);
+}
+
 static scm_t_bits
 scm_make_stptob ()
 {
index 22e9168..5f2625c 100644 (file)
@@ -76,7 +76,9 @@ SCM_API SCM scm_open_output_string (void);
 SCM_API SCM scm_get_output_string (SCM port);
 SCM_API SCM scm_c_read_string (const char *expr);
 SCM_API SCM scm_c_eval_string (const char *expr);
+SCM_API SCM scm_c_eval_string_in_module (const char *expr, SCM module);
 SCM_API SCM scm_eval_string (SCM string);
+SCM_API SCM scm_eval_string_in_module (SCM string, SCM module);
 SCM_API void scm_init_strports (void);
 
 #endif  /* SCM_STRPORTS_H */