On 13 Mrz., 12:03, "BENI" <rajib.chakraba... / googlemail.com> wrote: > I was trying to swig a function in ta-lib (TA-Lib provides common > functions for the technical analysis of financial market data)http://ta-lib.org/index.html > > the c functuon api > > TA_RetCode TA_MA( int startIdx, > int endIdx, > const double inReal[], > int optInTimePeriod, > int optInMAType, > int *outBegIdx, > int *outNbElement, > double outReal[], > ) > > =========== > > the c call > ========== > > TA_Real closePrice[400]; > TA_Real out[400]; > TA_Integer outBeg; > TA_Integer outNbElement; > > /* ... initialize your closing price here... */ > > retCode = TA_MA( 0, 399, > &closePrice[0], > 30,TA_MAType_SMA, > &outBeg, &outNbElement, &out[0] ); > > /* The output is displayed here */ > for( i=0; i < outNbElement; i++ ) > printf( "Day %d = %f\n", outBeg+i, out[i] ); > > ================ > > the query'''''' > > what should be the typemap > > for argument > > 1>const double inReal[], > 2>int *outBegIdx, > 3>int *outNbElement, > 4>double outReal[], > > ============= > > regards in ruby use it as closePrice = Array.new(<your data>) data_inp = closePrice[0..399] data_arr = ModuleExp::TA_MA( data_inp, 30, ModuleExp::TA_MAType_SMA) In .i file you should define %typemap(in)(int startIdx, int endIdx, const double inReal[] ) { Check_Type($input, T_ARRAY); /* Get the length of the array */ int size = RARRAY($input)->len; int i; $3 = (unsigned char*) malloc(size * sizeof(double)); $2 = size; $1 = 0; // copy the ruby array in the new allocated buffer /* Get the first element in memory */ VALUE *ptr = RARRAY($input)->ptr; for (i=0; i < size; i++, ptr++) { /* Convert Ruby Object Fixnum to unsigned char */ $1[i]= (double)?????(*ptr); // here i don't remember the macro to convert something like FIX2INT for float } } %typemap(in)(int optInMAType, int *outBegIdx, int *outNbElement, double outReal[] ) { int out_beg_ix = 0; int out_n_ele = 0; double arr_res[400]; $1 = NUM2INT(optInMAType); $2 = &out_beg_ix; $3 = &out_n_ele; &4 = arr_res; } %typemap(freearg) (int startIdx, int endIdx, const double inReal[], int optInTimePeriod, int optInMAType, int *outBegIdx, int *outNbElement, double outReal[]) { free((double *) $1); } %typemap(out)TA_RetCode TA_MA( int startIdx, int endIdx, const double inReal[], int optInTimePeriod, int optInMAType, int *outBegIdx, int *outNbElement, double outReal[] { int iStartIx = *arg6; int iLen = iStartIx + *arg7; VALUE arr = rb_ary_new2(iLen); for ( int i = iStartIx; i < iLen; i++ ) rb_ary_push(arr, INT2FIX((*arg8)[i])); $result = arr; } it is not tested but this give you the idea how to make the i file. Regards