[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Textal interface to Guile
From: |
Rob Browning |
Subject: |
Re: Textal interface to Guile |
Date: |
28 Apr 2001 18:32:36 -0500 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
jacques klein <address@hidden> writes:
> I just began to write "a quit (and dirty)" interface between a
> scripting language and Guile, using the gh_eval_str...() functions,
> but I cannot figure out how to "ALWAYS return the result in a C
> string" (like what I get when using guile interactively), or
> otherwise said, is there a function like gh_SCM_to_str() ? Thank's
> for any hint
Presuming I understand what you want, you could do several things
(note that I haven't tested any of these). You could define a
function to do the job for you:
char *
my_SCM_to_string(SCM obj)
{
static SCM scm_to_str = SCM_BOOL_F;
if(scm_to_str == SCM_BOOL_F) {
scm_to_str = gh_eval_str("
(lambda (x)
(with-output-to-string
(lambda ()
(write (x)))))");
scm_protect_object(scm_to_str);
}
return gh_scm2newstr(scm_to_str(obj), NULL);
}
or you could probably just use scm_simple_format:
#include <libguile/print.h>
...
my_str = gh_scm2newstr(scm_simple_format(SCM_BOOL_F,
gh_str02scm("~S"),
gh_list(my_obj, SCM_EOL)));
...
free(my_str);
Note that whether you want write or display in the first example or ~S
or ~A in the second example depends on what you're trying to do. Also
note that the info docs are a little buggy, and so I'm not sure
whether you're supposed to use SCM_EOL or SCM_UNSPECIFIED, though I
think SCM_EOL is right. It mentions both in different contexts.
--
Rob Browning <address@hidden> PGP=E80E0D04F521A094 532B97F5D64E3930