#ifndef ICI_CFUNC_H
#define ICI_CFUNC_H

#ifndef ICI_OBJECT_H
#include "object.h"
#endif

/*
 * The following portion of this file exports to ici.h. --ici.h-start--
 */

struct cfunc
{
    object_t    o_head;
    char        *cf_name;
    int         (*cf_cfunc)();
    int         (*cf_arg1)();
    char        *cf_arg2;
};
#define cfuncof(o)      ((cfunc_t *)(o))
#define iscfunc(o)      ((o)->o_type == &ici_cfunc_type)

/*
 * Convienience macro for use in static initialisations. Note that the
 * ici_cfunc_type pointer is patched in at run-time. This is only because
 * Windows has trouble making initialised address refs to data objects
 * across dynamic load boundaries.
 * ###Why is O_ATOM set?
 */
#define CF_OBJ          {0, O_ATOM, 1, 0, NULL}

/*
 * The n'th argument (first is 0) during execution of a function's C code.
 */
#define ARG(n)          (o_top[-2 - (n)])

/*
 * Count of actual arguments to this C function.
 */
#define NARGS()         (opof(x_top[-1])->op_code)

/*
 * A pointer to the first arg to this C function, decrement for next
 * and subsequent.
 */
#define ARGS()          (&o_top[-2])

/*
 * Return the cf_arg1 and cf_arg2 fields of the current C function.
 * The first is a function pointer, the second a char *.
 */
#define CF_ARG1()       (cfuncof(o_top[-1])->cf_arg1)
#define CF_ARG2()       (cfuncof(o_top[-1])->cf_arg2)

/*
 * End of ici.h export. --ici.h-end--
 */

#endif /* ICI_CFUNC_H */
