1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

(scm_object_to_string): Takes an optional argument.

This commit is contained in:
Keisuke Nishida 2001-03-13 05:59:42 +00:00
parent f7fd6a7389
commit fe78b6c096
2 changed files with 18 additions and 8 deletions

View file

@ -58,6 +58,7 @@
#include "libguile/root.h"
#include "libguile/strings.h"
#include "libguile/modules.h"
#include "libguile/validate.h"
#include "libguile/strports.h"
@ -311,17 +312,26 @@ SCM scm_strport_to_string (SCM port)
return scm_makfromstr ((char *) pt->read_buf, pt->read_buf_size, 0);
}
SCM_DEFINE (scm_object_to_string, "object->string", 1, 0, 0,
(SCM obj),
"Return a Scheme string obtained by printing a given object.")
SCM_DEFINE (scm_object_to_string, "object->string", 1, 1, 0,
(SCM obj, SCM printer),
"Return a Scheme string obtained by printing @var{obj}.\n"
"Printing function can be specified by the optional second\n"
"argument @var{printer} (default: @code{write}).")
#define FUNC_NAME s_scm_object_to_string
{
SCM str;
SCM port;
SCM str, port;
if (!SCM_UNBNDP (printer))
SCM_VALIDATE_PROC (2, printer);
str = scm_makstr (0, 0);
port = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_WRTNG, FUNC_NAME);
scm_prin1 (obj, port, 1);
if (SCM_UNBNDP (printer))
scm_write (obj, port);
else
scm_apply (printer, SCM_LIST2 (obj, port), SCM_EOL);
return scm_strport_to_string (port);
}
#undef FUNC_NAME
@ -331,7 +341,7 @@ SCM_DEFINE (scm_object_to_string, "object->string", 1, 0, 0,
SCM
scm_strprint_obj (SCM obj)
{
return scm_object_to_string (obj);
return scm_object_to_string (obj, SCM_UNDEFINED);
}
#endif /* (SCM_DEBUG_DEPRECATED == 0) */

View file

@ -50,7 +50,7 @@
extern SCM scm_mkstrport (SCM pos, SCM str, long modes, const char * caller);
extern SCM scm_strport_to_string (SCM port);
extern SCM scm_object_to_string (SCM obj);
extern SCM scm_object_to_string (SCM obj, SCM printer);
extern SCM scm_call_with_output_string (SCM proc);
extern SCM scm_call_with_input_string (SCM str, SCM proc);
extern SCM scm_read_0str (char *expr);