[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

accessing a printf-like function from scheme

From: Dan McMahill
Subject: accessing a printf-like function from scheme
Date: Tue, 25 Apr 2006 08:44:55 -0400
User-agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.7.6) Gecko/20050412


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

   "This is a %s message with %d args, pi is %g\n"

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)),
  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?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]