From: "Joachim (München)" Date: 2006-10-04T16:30:10+09:00 Subject: need help with narray: how to return an array from a C-extension Hi there, I am writing my first C extension module to ruby, and I need a little help: import of parameters works fine, but export of results not yet: static VALUE myarr_faltung1(VALUE m, VALUE distribution, VALUE lookuptable, VALUE mu_shifted) { struct NARRAY *a1, *a2; int mt, i; volatile VALUE v1, v2; /* import from parameters seems to work */ mt = NUM2INT(mu_shifted); v1 = na_cast_unless_narray(distribution,NA_DFLOAT); GetNArray(v1,a1); v2 = na_cast_unless_narray(lookuptable,NA_DFLOAT); GetNArray(v2,a2); /* calculation seems to work */ for (i=0; i<=1000; i++) *((double*)(a1->ptr+i)) += *((double*)(a2->ptr+mt-i)); /* PROBLEM: this does not work. QUESTION: how can I overwrite the call parameter "distribution" with a ruby array that contains the result a1->ptr of the above calculation? */ distribution = na_to_array( a1->ref ); /* PROBLEM: the following does not work either. QUESTION: how can I return the result a1->ptr of the above calculation to the calling program? */ return a1->ref ; } Thanks in advance, Joachim