M. Edward (Ed) Borasky
1/20/2008 4:39:00 AM
Axel Etzold wrote:
> Dear all,
>
> I'd like some advice about extending Ruby with C via SWIG ....
>
> I've got
>
> a.) a bunch of files written in C doing some form of division with
> remainder on a set of algebraic objects,
>
> b.) a bunch of code in Ruby determining which object from the
> set above to divide by which other next.
Is your C code one of the "well-known" open source libraries that do
this kind of computation, or is it home-grown? The reason I ask is that
there are quite a few Python interfaces to the well-known libraries, and
it would be relatively easy to port some of them to Ruby.
> Now I could use SWIG to write a C extension of Ruby to connect
> the two. I've read tutorials about that and it seems to
> work, tentatively.
SWIG requires detailed knowledge of the C or C++ API of your libraries
to be used effectively. However, once you get your SWIG interface
descriptions written, you can embed the library in just about all the
major scripting languages with little extra effort. If you're only
interested in a Ruby interface, SWIG might be a lot more effort than you
need.
>
> But I've got an additional issue.
> The algebraic objects are polynomials, i.e., objects
> a_0 + a_i x + ... + a_n x^n, where the coefficients a_i can so far
> only be integers (big numbers allowed), according to the existing C code.
> But I must be able to use other coefficients as well, such as
> fractions (adding them needs common denominators), floats,
> and complex numbers.
>
> What do you think is an economical way of telling C about
> Ruby Rational(x,y) or Complex(x,y) or Float coefficients and
> returning the results ?
>
> Thank you very much!
>
> Best regards,
>
> Axel
One other note -- have you looked at RubyInline?