# Extending ta-lib using SWIG

**URL:** <https://www.ruby-forum.com/t/extending-ta-lib-using-swig/88639>\
**Category:** Ruby\
**Created:** [March 13, 2007, 9:25am UTC](https://www.ruby-forum.com/t/extending-ta-lib-using-swig/88639 "2007-03-13T09:25:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BENI](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BENI](https://www.ruby-forum.com/u/BENI)\
**Post date:** [March 13, 2007, 9:25am UTC](https://www.ruby-forum.com/t/extending-ta-lib-using-swig/88639/1 "2007-03-13T09:25:28Z")

</div>

ta-lib ([http://ta-lib.org/](http://ta-lib.org/)) is a package availiable which has port for  
perl,python?,excel etc.

I needed it in ruby… since no port is availiable (AFAIK) … i  
thought of building a port.

i have read along the pickaxe book of extending ruby…

after evaluating all the options i thought i will give SWIG a shot…

given the header like

# ================================================= TA\_RetCode TA\_MA( int START\_IDX, int END\_IDX, const double _IN\_ARRAY /_ inReal _/, int OPT\_INT /_ optInTimePeriod _/, /_ From 1 to 100000 _/ TA\_MAType OPT\_MATYPE /_ optInMAType \*/, int \*BEG\_IDX, int \*OUT\_SIZE, double _OUT\_ARRAY /_ outReal \*/ );

# in C it can be called like

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] );

=======================

* * *

could any one give me a lead how should the typemap for \*IN\_ARRAY look  
like?

# for python the typemap for \*IN\_ARRAY looks like

%typemap(in) const double \*IN\_ARRAY  
{  
int array\_size = endIdx2 + 1;

```
$1 = ($1_ltype) calloc(array_size, sizeof($*1_ltype));
if (!convert_darray($input, $1, array_size)) goto fail;

```

# }

cheers

Rajib
