It need not be too bad. Here's an Inline::C demo where the function has a FILE* as it's first argument, a string as its second argument, and a variable number of following arguments (all of which are unsigned integers). If you want to see what a valid XS file looks like just uncomment  # CLEAN_AFTER_BUILD => 0, (before you have run the script) and take a look in the _Inline/build directory at the XS file that was autogenerated.
Update: Script modified slightly from when first posted
### try.pl ### use warnings; use Inline C => Config => # CLEAN_AFTER_BUILD => 0, BUILD_NOISY => 1; use Inline C => <<'EOC'; void foo(FILE * fh, SV* sv, ...) { dXSARGS; int i, arg; printf("%s ", SvPV_nolen(ST(1))); for (i = 2; i < items; i++) { arg = SvUV(ST(i)); printf("%d ", arg); } XSRETURN(0); } EOC open($rd, '<', 'try.pl') or die $!; $fmt = "foobar"; foo($rd, $fmt, 1 .. 5); print "\n"; foo($rd, $fmt, 21 .. 32); print "\n";
But there's a problem ... what if the third and subsequent args aren't all unsigned integers ? What if they're an ad hoc mixture of integers, doubles, and strings ?

That obviously complicates things. You might be able to convert each of those arguments to the appropriate C type by examining the flags associated with them. Or, you might be able to derive that info by decoding the fmt string (2nd arg). Either way, it's not all that pretty. (I don't know of any other way - but that doesn't mean that an alternative doesn't exist.)

Cheers,
Rob

In reply to Re: C Functions with variable argument list in perlxs by syphilis
in thread C Functions with variable argument list in perlxs by Temeschwarrior

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.