I am new to Perl XS and I am trying to convert a C function to Perl subroutine.
I have the following C function
void parse(struct parser *result, const char *string, size_t len);
where the parse
function accepts a pointer to struct parser
, a string and the length of the string. struct parser
is defined something like this:
struct parser {
char *data;
long a;
long b;
long c;
};
The function stores its results in the result
argument.
I want to convert this function to Perl XS. What I am doing is something like this:
struct parser *result
parse_xs (string)
const char* string
PREINIT:
long len = strlen(string);
CODE:
struct parser par;
parse(&par,s,len);
RETVAL = par;
OUTPUT:
RETVAL
How can I change the above code to run parse_xs
in Perl code like this
my $result = parse_xs();
print $result->data; # will print the data field from the struct.
where $result
is the result of the parse
C function.