ruby extension best practices

Discussion in 'Ruby' started by leon breedt, Nov 15, 2004.

  1. leon breedt

    leon breedt Guest

    hi,

    i am about to create an extension for a third party API (API is pretty
    consistent), was wondering what the best practices are.

    are there tools for generating the glue for methods on classes i
    create to wrap the various abstractions?

    is there something like Pyrex for Ruby? (google didn't really come up
    with anything conclusive).

    what is the most "modern" way of creating extensions without making
    too much work for myself such that it is difficult to maintain?

    when is it a good idea to use Ruby/DL and when not?

    thanks
    leon
     
    leon breedt, Nov 15, 2004
    #1
    1. Advertising

  2. leon breedt

    Tim Hunter Guest

    Tim Hunter, Nov 15, 2004
    #2
    1. Advertising

  3. leon breedt wrote:
    > hi,
    >
    > i am about to create an extension for a third party API (API is pretty
    > consistent), was wondering what the best practices are.
    >
    > are there tools for generating the glue for methods on classes i
    > create to wrap the various abstractions?
    >
    > is there something like Pyrex for Ruby? (google didn't really come up
    > with anything conclusive).
    >
    > what is the most "modern" way of creating extensions without making
    > too much work for myself such that it is difficult to maintain?
    >
    > when is it a good idea to use Ruby/DL and when not?


    Check out SWIG. It can do most of the work for you, generating wrappers
    for the 3rd party API.

    Another possibility, is cgen (on RAA) which I wrote to provide a ruby
    interface to the ruby C API. It was intended for code generation rather
    than wrapping, so it might be a better choice if you are generating an
    extension from scratch. I have used it with an existing library, though.
     
    Joel VanderWerf, Nov 15, 2004
    #3
  4. leon breedt

    Phil Tomson Guest

    In article <>,
    leon breedt <> wrote:
    >hi,
    >
    >i am about to create an extension for a third party API (API is pretty
    >consistent), was wondering what the best practices are.
    >
    >are there tools for generating the glue for methods on classes i
    >create to wrap the various abstractions?
    >
    >is there something like Pyrex for Ruby? (google didn't really come up
    >with anything conclusive).
    >


    How about RubyInline?
    http://rubyforge.org/projects/rubyinline/

    >what is the most "modern" way of creating extensions without making
    >too much work for myself such that it is difficult to maintain?
    >
    >when is it a good idea to use Ruby/DL and when not?


    If your 3rd party shared library is written in C and not C++, Ruby/DL might be
    the way to go since, as you say the library is well documented.

    Phil
     
    Phil Tomson, Nov 15, 2004
    #4
  5. leon breedt

    leon breedt Guest

    thanks for all the suggestions, SWIG seems to be closest to what i
    want (the others seem to be fine for small amounts of interfacing, but
    i want a fair amount of API coverage and with library data types
    mapped to Ruby classes).

    in short, i just want something that does the
    Data_Wrap_Struct/Data_Get_Struct magic for me, as well as the C<->Ruby
    type marshaling. SWIG would appear to have this as a goal, buti'm
    having some problems with it.

    the library uses opaque structs for the most part.

    i can't seem to indicate that i want an opaque struct of a particular
    type to be mapped to a Ruby class, and methods taking the opaque
    struct pointer as an argument to become instance methods of that
    class.

    i tried this using %extend, but that errors out when given an opaque
    struct, it wants a struct body, defeating the whole point of using
    SWIG, and breaking the signature of library methods.

    anyone have any experience with SWIG used like this?

    leon
     
    leon breedt, Nov 16, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. karim
    Replies:
    0
    Views:
    467
    karim
    Jul 13, 2003
  2. John Dalberg
    Replies:
    3
    Views:
    576
    samuelhon
    Nov 16, 2006
  3. harshal
    Replies:
    9
    Views:
    203
    Pedro Del Gallego
    Mar 11, 2008
  4. Gregory Brown
    Replies:
    0
    Views:
    90
    Gregory Brown
    Jan 10, 2009
  5. Chicken McNuggets

    Best book on C gotchas and best practices?

    Chicken McNuggets, Jul 31, 2013, in forum: C Programming
    Replies:
    9
    Views:
    270
    Fred J. Tydeman
    Aug 5, 2013
Loading...

Share This Page