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

int chcallfuncbyaddr_1(ChInterp_t interp, void * func_chdl_fptr) {
  int retval, j, k;
  int a[3] = {1,2,3,};
  int b[3][4] = {1,2,3,4, 
                 5,6,7,8,
                 9, 10, 11, 12};

  Ch_CallFuncByAddr(interp, func_chdl_fptr, &retval, a, 1, 3, b, 2, 3, 4);

  printf("\nIn the dynamically loaded object:\n");
  for(j=0; j<3; j++) 
    printf("a[%i] = %d\n", j, a[j]);
  for(j=0; j<3; j++) {
    for(k=0; k<4; k++) {
      printf("b[%i][%i] = %d\n", j, k, b[j][k]);
    }
  }  
  return 0;
}

EXPORTCH int chcallfuncbyaddr_1_chdl(void *varg) {
  ChInterp_t  interp;
  void *func_chdl_fptr;
  ChVaList_t ap;
  int retval;
  Ch_VaStart(interp, ap, varg);
  func_chdl_fptr = Ch_VaArg(interp, ap, void *);   /* get pointer of func  */
  retval = chcallfuncbyaddr_1(interp, func_chdl_fptr);
  
  Ch_VaEnd(interp, ap);
  return retval;
}

