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.
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?