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

int cfun1(ChInterp_t interp, void *chfunptr){
   int dim, ext1, ext2;
   int sum_ret;
   int aa1[2][3] = { 1, 2, 3, 
                    4, 5, 6};

   int aa2[3][4] = { 1, 2, 3, 4,
                     5, 6, 7, 8,
                     9, 10, 11, 12};

   dim = 2, ext1 = 2; ext2 = 3; /* dim and extents of aa1 */
   Ch_CallFuncByAddr(interp, chfunptr, &sum_ret, aa1, dim, ext1, ext2);
   printf("sum2d has been called from C space and returned %d\n\n", sum_ret);

   dim = 2, ext1 = 3; ext2 = 4; /* dim and extents of aa2 */
   Ch_CallFuncByAddr(interp, chfunptr, &sum_ret, aa2, dim, ext1, ext2);
   printf("sum2d has been called from C space and returned %d\n", sum_ret);

   return 0;
}   

EXPORTCH int callchvla_2d_chdl(void *varg) {
  ChInterp_t interp;
  ChVaList_t ap;
  int retval;
  void *sum2d_ch_fun;

  Ch_VaStart(interp, ap, varg);
  sum2d_ch_fun = Ch_VaArg(interp, ap, void *);

  retval = cfun1(interp, sum2d_ch_fun);
  Ch_VaEnd(interp, ap);
  return retval; 
}
