From: ara.t.howard@... Date: 2006-09-21T23:11:12+09:00 Subject: Re: Assistance wanted for integrating existing C-API into Ruby On Thu, 21 Sep 2006, Feurio wrote: > Hello, > > I am seeking assistance for writing a ruby wrapper for the c-api of an > existing enterprise system. This job is a paid job. > > > In my vision the access from ruby/rails to this existing system should be > like working with active record. Basically I think there should be a ruby > layer to make the c-api accessible and another that integrates it with > Active Record. I think this makes sense because my main focus is to access > the data of the enterprise system. > > > For the first layer I can imagine to use SWIG (this seems to be a good way > to integrate a c-api from ruby; but if you know a better way just tell me) if the api is simple, or even moderately simple, you may be able to wrap it this afternoon using ruby/dl - which allows one to call c functions __directly__ from ruby without any glue (swig) code. here's an example which calls atoi(3): harp:~ > cat a.rb require "dl/import" require "dl/struct" module LIBC extend DL::Importable begin dlload "libc.so.6" rescue dlload "libc.so.5" end extern "int atoi(char*)" end p LIBC.atoi("42") harp:~ > ruby a.rb 42 if you take this approach you'd probably be best off doing something like one_to_one_mapping_of_c_to_ruby = Module.new{ # # as the example above # }.unit_test! then high_level_interface = Module.new{ # # use one_to_one_mapping_of_c_to_ruby to provide high level functions # }.unit_test! swig is a fine peice of software but, sometimes, there's no need to actually write/generate an extension. kind regards. -a -- in order to be effective truth must penetrate like an arrow - and that is likely to hurt. -- wei wu wei