|
XSUBs can have variable-length parameter lists by specifying an ellipsis (...)
in the parameter list. This use of the ellipsis is similar to that found in ANSI C. The
programmer is able to determine the number of arguments passed to the XSUB by examining the items
variable which the xsubpp compiler supplies for all XSUBs. By using this mechanism one
can create an XSUB which accepts a list of parameters of unknown length.
The host parameter for the rpcb_gettime() XSUB can be optional so the ellipsis can
be used to indicate that the XSUB will take a variable number of parameters. Perl should be
able to call this XSUB with either of the following statements.
$status = rpcb_gettime( $timep, $host );
$status = rpcb_gettime( $timep );
|
|
The XS code, with ellipsis, follows.
bool_t
rpcb_gettime(timep, ...)
time_t timep = NO_INIT
PREINIT:
char *host = "localhost";
STRLEN n_a;
CODE:
if( items > 1 )
host = (char *)SvPV(ST(1), n_a);
RETVAL = rpcb_gettime( host, &timep );
OUTPUT:
timep
RETVAL
|
|
|
|