# Ta-lib port with swig

**URL:** <https://www.ruby-forum.com/t/ta-lib-port-with-swig/88653>\
**Category:** Ruby\
**Created:** [March 13, 2007, 11:11am UTC](https://www.ruby-forum.com/t/ta-lib-port-with-swig/88653 "2007-03-13T11:11:42Z")\
**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, 11:11am UTC](https://www.ruby-forum.com/t/ta-lib-port-with-swig/88653/1 "2007-03-13T11:11:42Z")

</div>

ta-lib is a collection of math/statistical function library for price  
variability analysis written in C.

There is no port availiable for it in ruby.

Since i badly needed one … so i started researching on.

I went along the pickaxe book.  
since there are about 120 odd functions to port … I was thinking to  
embark upon the SWIG.

I read along the SWIG docs and ruby mailing list for hints but  
somehow could not zero upon how to kick start.

# one of the function header looks like this

# TA\_RetCode TA\_MA( int startIdx, int endIdx, const double inReal[], int optInTimePeriod, int optInMAType, int \*outBegIdx, int \*outNbElement, double outReal[], )

this is called from c in this way

=======================  
Lets say you wish to calculate a 30 day moving average using closing  
prices. The function call could look as follow:

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

given this I was wondering If I would need to write some typemaps for  
SWIG or the typemap.i inclusion will be sufficient?

Specifically…

In the C function above the \<const double inReal[]\> argument is  
passed as &closePrice[0] … In ruby i won’t be able to do that… I  
will have to pass in an array containing… double… how do i do that  
using typemap?

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

Cheers

Rajib
