Trying to get the hang of this xs stuff and at a hump I can't seem to get over ...
Modifying a passed parameter.
The goal is to return the Int value and modify the passed arg to true or false (pass or fail on the conversion)
MyLib is a stupid simple string class, strToInt() works correctly, both in the return value as well as modifying the passfail value.
However, It does not show the changes in Perl.
The xs code. (with some printf's)
int MyLib::strToInt(passfail) bool passfail; CODE: if(passfail) { printf("It's true in xs. %i\n", passfail); } else { printf("It's false in xs. %i\n", passfail); } RETVAL = THIS->strToInt(&passfail); if(passfail) { printf("It's true out xs. %i\n", passfail); } else { printf("It's false out xs. %i\n", passfail); } OUTPUT: RETVAL passfail
The Perl calling code.
my $passfail = 0; my $tmp = MyLib->new("12"); my $t = $tmp->strToInt(\$passfail); print "It's $t\n" if $passfail eq 1;
The above code produces the following output:
So the xs and C code worksIt's false in xs. 0 It's true out xs. 1
What the blazes am I doing wrong!
Perlxstut makes it look simple ...
Thanks
-Enjoy
fh : )_~
In reply to xs modifying passed value by Festus Hagen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |