I canβt say if this is a mistake or what.
The following code works with Inline::C
, but not Inline::CPP
#!/usr/bin/perl use warnings; use Inline C; my @array = (1..10); print findAvLen(\@array), "\n"; __END__ __C__ int findAvLen(AV* arrayIn) { return av_len(arrayIn); }
The above works fine, but replace C
with CPP
and I get the error Can't locate auto/main/findAvLen.al in @INC...
I can use other C ++ inline code. For example, you can pass a list of variables into inline code with an ellipsis, since they are in this example , but I wonder why AV * does not work! For example, I want to use a routine to convert perl arrays passed in C ++ to vectors, for example. void perl2vector(AV* ar, std::vector<T> &v) {...}
, instead of inserting code to perform such a conversion into every C ++ function, I write that takes an array argument. How can I use this example syntax to pass a perl array to such a converter?
This seems like an error, but at the same time, uesp discovered a workaround:
int findAvLen(SV* arrRef) { AV * arr = MUTABLE_AV(SvRV(arrRef)); return av_len(arr); }
arr
now equivalent to arrayIn
specified in the above example.
source share