From: Gurusamy Sarathy Date: Mon, 21 Feb 2000 18:31:42 +0000 (+0000) Subject: allow optional XSUB parameters without being forced to use a X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4628e4f8c013135d9c9ab7023d7730ab67289444;p=p5sagit%2Fp5-mst-13.2.git allow optional XSUB parameters without being forced to use a default (from Hugo van der Sanden) p4raw-id: //depot/perl@5183 --- diff --git a/lib/ExtUtils/xsubpp b/lib/ExtUtils/xsubpp index 431d75a..4ff0d38 100755 --- a/lib/ExtUtils/xsubpp +++ b/lib/ExtUtils/xsubpp @@ -1576,7 +1576,11 @@ sub generate_init { eval qq/print "\\t$var;\\n"/; warn $@ if $@; } - $deferred .= eval qq/"\\n\\tif (items < $num)\\n\\t $var = $defaults{$var};\\n\\telse {\\n$expr;\\n\\t}\\n"/; + if ($defaults{$var} eq 'undef') { + $deferred .= eval qq/"\\n\\tif (items >= $num) {\\n$expr;\\n\\t}\\n"/; + } else { + $deferred .= eval qq/"\\n\\tif (items < $num)\\n\\t $var = $defaults{$var};\\n\\telse {\\n$expr;\\n\\t}\\n"/; + } warn $@ if $@; } elsif ($ScopeThisXSUB or $expr !~ /^\t\$var =/) { if ($name_printed) { diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 2dd496a..42bbd46 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -4362,7 +4362,7 @@ and the conversion letter: h interpret integer as C type "short" or "unsigned short" If no flags, interpret integer as C type "int" or "unsigned" -There is also two Perl-specific flags: +There are also two Perl-specific flags: V interpret integer as Perl's standard integer type v interpret string as a vector of integers, output as diff --git a/pod/perlxs.pod b/pod/perlxs.pod index a2755b8..2055ce6 100644 --- a/pod/perlxs.pod +++ b/pod/perlxs.pod @@ -502,9 +502,9 @@ C. =head2 Default Parameter Values -Default values for XSUB arguments can be specified by -placing an assignment statement in the parameter list. The -default value may be a number or a string. Defaults should +Default values for XSUB arguments can be specified by placing an +assignment statement in the parameter list. The default value may +be a number, a string or the special string C. Defaults should always be used on the right-most parameters only. To allow the XSUB for rpcb_gettime() to have a default host @@ -1314,6 +1314,19 @@ methods will be called as this: THIS->set_blue( val ); +You could also write a single get/set method using an optional argument: + + int + color::blue( val = undef ) + int val + PROTOTYPE $;$ + CODE: + if (items > 1) + THIS->set_blue( val ); + RETVAL = THIS->blue(); + OUTPUT: + RETVAL + If the function's name is B then the C++ C function will be called and C will be given as its parameter. The generated C++ code for