|Pathologically Eclectic Rubbish Lister|
Re^3: Perl XSby syphilis (Chancellor)
|on Nov 19, 2013 at 00:11 UTC||Need Help??|
Inline::C can still be helpful - as a quick way of discovering what's going wrong and testing proposed fixes.
For example, I placed (copy'n'paste') your 2 functions in an Inline::C script:
When I run that script, it compiles, then outputs:
The problem is that, although there's nothing syntactically wrong with print_array_int(), perl doesn't know how to pass the 'int array' type to XS.
For a working solution, you need to know a little bit about the perl API. I suggest perlxs, perlxstut, and perlapi docs, though you'll perhaps also find some useful tips in the Inline::C cookbook and, no doubt, many other places.
Anyway, here's one solution:
"items" is the number of elements on the stack - so there's really no need to pass the length of the array to the function. You could remove that arg and rewrite the for loop condition as (i=0; i<items; i++)
Two things to note about Inline::C:
1) It's really just XS - it takes your C code, autogenerates the XS code, then compiles and runs your program.
2) Inline::C defines its own stack macros, all of which begin with "Inline_Stack_" and are defined in the Inline.h file that it also autogenerates. Other than that, it's the same as XS, and you don't *have* to use its stack macros. You can just use the normal XS terms - as I did above when I declared "dXSARGS" instead of "Inline_Stack_Vars" (and used "XSRETURN(0)" instead of "Inline_Stack_Void").