/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
#include<ch.h>
#include<stdio.h>
#include<stdarg.h>

ChInterp_t interp;

/* this function Some_API() is exported and documented for user */
int Some_API(char *funcname, void *retval, ...) {
  va_list ap;

  va_start(ap, retval);
  /* call Ch function by its name */
  Ch_CallFuncByNamev(interp, funcname, retval, ap);
  va_end(ap);
}

void call_API() { /* test and use Some_API() */
  int funret;
  double d;

  /* call Ch function by its name */
  Some_API("chfun", &funret, 20);
  printf("The return value in C space from Ch function chfun(20) is %d\n", funret); 

  /* call Ch function in function file */
  Some_API("hypot", &d, 3.0, 4.0);
  printf("The return value in C space from Ch function hypot(3,4) is %f\n", d);
}

EXPORTCH void chcallfuncbynamev_chdl(void *varg) {
  ChVaList_t ap;

  Ch_VaStart(interp, ap, varg); 
  call_API();
  Ch_VaEnd(interp, ap);
  return;
}
