Monks;
I have just started dabbling with XS, and I've run into a snag. I want to change the way I'm calling the XS routine to use named parameters instead of positional parameters. So instead of this:
calculate('V_MIN',4.5);
I can do this:
calculate(NAME => 'V_MIN', THETA => 4.5);
I've looked at perlxs, but haven't found a way to do this. I want to be anle to get the values from the passed-in hash for keys "NAME" and "THETA". Here's my best quess thus far:
int calculate(hash) HV * hash; CODE: char * name; float theta; name = (char *)hv_fetch(hash,"NAME",4,0); theta = hv_fetch(hash,"THETA",5,0); printf("%s,%.1f\n",name,theta); . . . RETVAL = 1; OUTPUT: RETVAL
...but it won't even compile. I get errors:
ChemC.xs: In function `XS_ChemC_calculate': ChemC.xs:122: parse error before `char' ChemC.xs:125: `name' undeclared (first use in this function) ChemC.xs:125: (Each undeclared identifier is reported only once ChemC.xs:125: for each function it appears in.) ChemC.xs:126: `theta' undeclared (first use in this function) make: *** [ChemC.o] Error 1
Can anyone help?
Nelson

In reply to XS hash question by Anonymous Monk

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.