Using Array Value (AV) functions, it's possible to access Perl arrays in C. The following code snippet copies integer values from Perl into a typical C int array.
void
set_site_divider(site_divider)
AV* site_divider
CODE:
I32 l = av_len(site_divider) + 1;
unsigned int *cpy = malloc(sizeof(*cpy) * l);
int i = 0;
for (; i < l; i++) {
SV *site = av_shift(site_divider);
cpy[i] = SvIV(site);
}
set_site_divider(cpy);av_shift pops the first scalar value (SV) from the array, and SvIV returns the int value stored in the scalar.
The document perlguts contains more functions to manipulate SV's and AV's.
For referance, the C function:
void set_site_divider(unsigned int *s) {
site_divider = s;
}And the function call from perl:
DocInfo::Store::set_site_divider([5, 6, 7, 8, 9]);:o
ABC = ABC
PRINT ABC