* accessing a printf-like function from scheme
@ 2006-04-25 12:44 Dan McMahill
2006-04-25 14:00 ` Tomas Zerolo
2006-04-25 14:27 ` William Xu
0 siblings, 2 replies; 3+ messages in thread
From: Dan McMahill @ 2006-04-25 12:44 UTC (permalink / raw)
Hello,
I'm trying to provide scheme access to a C function which has the same
interface a printf(). What I'd like to do in scheme is something like
(gschem-log
"This is a %s message with %d args, pi is %g\n"
"log"
3
3.14
)
so I've gotten as far as a function which takes a variable number of
arguments and made it available from scheme but can't seem to figure out
the last step which is how to get the elements from the :
SCM g_funcs_log(SCM s_num_list)
{
SCM s_element;
int length;
int i;
/* Check that the input is a list */
SCM_ASSERT (SCM_NFALSEP (scm_list_p (s_num_list)),
s_num_list,
SCM_ARG1,
"gschem-log");
length = scm_num2int(scm_length(s_num_list), 0, "g_funcs_log()");
if (length == 0)
return SCM_BOOL_T;
/* how to actully feed the data to s_log_message which
* has a printf-like interface
*/
s_log_message ("Hi there. Length = %d\n", length);
return SCM_BOOL_T;
}
scm_c_define_gsubr ("gschem-log", 0, 0, 1, g_funcs_log);
If it would be easier I can also write a
void s_log_messagev (const char * restrict format, va_list ap);
to complement the
void s_log_message(const char * restrict format, ...);
I tried to find some sort of scm_list2_c_va_list() but haven't found it yet.
Any suggestions?
Thanks
-Dan
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: accessing a printf-like function from scheme
2006-04-25 12:44 accessing a printf-like function from scheme Dan McMahill
@ 2006-04-25 14:00 ` Tomas Zerolo
2006-04-25 14:27 ` William Xu
1 sibling, 0 replies; 3+ messages in thread
From: Tomas Zerolo @ 2006-04-25 14:00 UTC (permalink / raw)
Cc: guile-user
[-- Attachment #1.1: Type: text/plain, Size: 1424 bytes --]
On Tue, Apr 25, 2006 at 08:44:55AM -0400, Dan McMahill wrote:
>
> Hello,
>
> I'm trying to provide scheme access to a C function which has the same
> interface a printf(). [...]
> SCM g_funcs_log(SCM s_num_list)
> {
> SCM s_element;
> int length;
> int i;
>
> /* Check that the input is a list */
> SCM_ASSERT (SCM_NFALSEP (scm_list_p (s_num_list)),
> s_num_list,
> SCM_ARG1,
> "gschem-log");
> length = scm_num2int(scm_length(s_num_list), 0, "g_funcs_log()");
>
> if (length == 0)
> return SCM_BOOL_T;
>
> /* how to actully feed the data to s_log_message which
> * has a printf-like interface
> */
> s_log_message ("Hi there. Length = %d\n", length);
>
> return SCM_BOOL_T;
> }
I fear there is no portable way for this...
> If it would be easier I can also write a
>
> void s_log_messagev (const char * restrict format, va_list ap);
>
> to complement the
>
> void s_log_message(const char * restrict format, ...);
>
> I tried to find some sort of scm_list2_c_va_list() but haven't found it yet.
>
> Any suggestions?
I'm not aware of a portable way of putting together a va_list (just of
taking it apart). And I wouldn't expect to see one -- C compilers do a
lot of obscure stuff to optimize parameter passing.
Maybe your function needs another interface (e.g. an array of params)?
Regards
-- tomás
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
[-- Attachment #2: Type: text/plain, Size: 140 bytes --]
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: accessing a printf-like function from scheme
2006-04-25 12:44 accessing a printf-like function from scheme Dan McMahill
2006-04-25 14:00 ` Tomas Zerolo
@ 2006-04-25 14:27 ` William Xu
1 sibling, 0 replies; 3+ messages in thread
From: William Xu @ 2006-04-25 14:27 UTC (permalink / raw)
Dan McMahill <mcmahill@mtl.mit.edu> writes:
> I'm trying to provide scheme access to a C function which has the same
> interface a printf(). What I'd like to do in scheme is something like
But, doesn't SLIB already have this?
(info "(slib) Standard Formatted Output")
--
William
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-04-25 14:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-25 12:44 accessing a printf-like function from scheme Dan McMahill
2006-04-25 14:00 ` Tomas Zerolo
2006-04-25 14:27 ` William Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).