On Fri, 20 May 2005, Colin Paul Adams wrote:

   Leopold> <void * Parrot_runops_fromc_arglist(Parrot_Interp
   Leopold> interpreter, PMC *sub, const char *sig, va_list args)>
And as for hand-writing interfaces, I'm not sure I know HOW to create
a va_list.

void *Parrot_runops_fromc_argsN(Parrot_Interp i, PMC *sub, const char *sig, ...) { void *result; va_list ap; va_start(ap, sig); result = Parrot_runops_fromc_arglist(i,sub,sig,ap); va_end(ap); return result; } void *Parrot_runops_fromc_args0(Parrot_Interp i, PMC *sub, const char *sig){ return Parrot_runops_fromc_argsN(i, sub, sig); } void *Parrot_runops_fromc_args1(Parrot_Interp i, PMC *sub, const char *sig, void **args){ return Parrot_runops_fromc_argsN(i, sub, sig, args[0]); } void *Parrot_runops_fromc_args2(Parrot_Interp i, PMC *sub, const char *sig, void **args){ return Parrot_runops_fromc_argsN(i, sub, sig, args[0], args[1]); } /* .. etc .. */ typedef void (*pf_t)(Parrot_Interp i, PMC *sub, const char *sig, void **args);

void *Parrot_runops_fromc_args(Parrot_Interp i, PMC *sub, const char *sig,
                               void **args, int num_args){
  static const pf_t dispatch[] = { Parrot_runops_fromc_args0,
                                   Parrot_runops_fromc_args1,
                                   Parrot_runops_fromc_args2,
                                   /* ... etc ... */ };
  assert(num_args < (sizeof(dispatch)/sizeof(*dispatch)));
  return (dispatch[num_args])(i, sub, sig, args);
}

--------------------
See?  Easy! =)

Of course, if your arguments array is not homogeneous, this scheme gets more complicated (that's why the va_list is being used to start with),
but it's still quite possible. It is very rare to find functions of more than, say, 10 arguments.
--scott


Echelon JMBLUG GRALLSPICE cryptographic KUGOWN Waihopai HBDRILL ESODIC SEAL Team 6 Nader Bush LICOZY RUCKUS Sabana Seca ODEARL COBRA JANE
( http://cscott.net/ )

Reply via email to