From: Derek Ney Date: 2002-09-18T09:55:23+09:00 Subject: Ruby and inline C or C++ All of this talk in regards to RubyInline made me start thinking about combining C (or C++) and Ruby. I have been working with Ruby for some time now and it is amazing how much fun it is to program with Ruby (as compared to my years of toil with C and C++ and forays into Perl). I would like to use Ruby in all of my programming, but unfortunately, my domain at work is image processing (routinely working with 3D data of hundreds of mega-voxels) and performance is key. To use Ruby for this domain, the only real option, of course, is to mix Ruby and C (or C++), perhaps via SWIG or things like RubyInline or cgenerator. And this would probably be a reasonable way to approach it. But, what if we took things further and integrated the use of C or C++ into Ruby itself. If we fully integrated C and C++ into Ruby there would be no problem domain which it could not cover. Here is what I had in mind: module ImageProcessing class Image # lots of defs here end # Add v to each image pixel, assumes images are 8 bits/pixel cdef void add(VALUE image, unsigned char v) unsigned char *pix = rb_funcall(image, rb_intern("pixel_ptr"), 0); long n_pixels = rb_funcall(image, rb_intern("n_pixels"), 0); for(long i=0; ipixel_ptr(); long n_pixels = image->n_pixels(); for(long i=0; i