#include <sample.h>
#include <ch.h>

static ChInterp_t interp;
static int fp_funarg(int n);
static void *fp_funptr;

EXPORTCH int func3_chdl(void *varg) {
    ChVaList_t ap;
    FUNPTR fp_ch, fp_c;
    int n;
    int retval;

    Ch_VaStart(interp, ap, varg);
    fp_ch = Ch_VaArg(interp, ap, FUNPTR);
    n = Ch_VaArg(interp, ap, int);
    fp_funptr = (void *)fp_ch;
    if (fp_ch != NULL)  {
        fp_c = (FUNPTR)fp_funarg;
    }
    retval = func3(fp_c, n);
    Ch_VaEnd(interp, ap);
    return retval;
}

static int fp_funarg(int n) {
     int retval;
     Ch_CallFuncByAddr(interp, fp_funptr, &retval, n);
     return retval;
}
