From: <tn...@fa...> - 2011-08-17 05:11:27
|
Hello, Say you have a function takes values from an array, transforms the value and stores it in another array, like void transform(const int k, const in[], int out[]) { int i; for (i=0; i<k; i++) out[i]=in[i]*2; // or whatever... } I want to be able to call this function as (from perl in my case): my $x = swigmod::transform([1,2,3,4]); # $x is now [2,4,6,8] I can't figure out how to accomplish this without having to manually write a C wrapper function, or forcing the scripting language user to pass an array preallocated with k elements. I thought I could write something analogous to non-array argouts, like this: %typemap(argout) double *OUTPUT { $result = sv_2mortal(newSVnv(*$1)); argvi++; } %typemap(in,numinputs=0) double *OUTPUT(double junk) { $1 = &junk; } But for arrays, I would need to allocate an appropriately sized 'double * junk', which I can't do b/c I don't have access to the length from within the typemap code (I know I can access the length variable k with something like 'k_0' where 0 is the position of 'k', but that seems extremely dirty). I would also need to know the length in the argout. Any ideas? Or am I approaching this the wrong way? -Tom |