Wrapping Ruby around OLD code

Lähettäjä: gw <gw@citasystems.com>
5 years ago one of our smart guys suggested we throw away our home grown "Basic" which glues our
many software actions into a seeming whole. We had over the years created many verbs that are
activated by special names. The "Basic" glue became more and more important and it was pointed out
that our specialties should be the verbs NOT the "Basic". At that time Python was suggested as a
replacement for our proprietary "Basic".

Here it is 5 years later and our programming staff is very small and the ancientness of our "Basic"
MUST be dealt with. I am giving some consideration to Ruby, though I *know* that Python would do
OK. I have programmed in many languages and I now include Python as one I know well enough.

I am initially attracted to Ruby because it promises more fewer special cases in syntax and its
more purely object orientation. Not the least is it has not exploded (yet) to the point of being
nearly impossible for a programmer to walk all the way round language.

Here is my question: Embedding our OLD code into Ruby is how big a chore? A lot of this code dates
from the late 1980's and is in NO WAY object oriented. Python seems like it might let me get away
with embedding old code without make major complaints. Have any of you attempted to incorporate
procedural code (tied together with global variables) into Ruby? I would understand if
knowledgeable programmers plead with me to not sully Ruby's name by attempting this Frankenstein.
However, I want the power of new life for our "specialty verbs" that a modern, supported
"scripting" language would provide.

One thing to consider is the model of your software: I'm not
quite clear if this 'BASIC' of yours coordinates actions between
independent programs or just libraries or even parts of the same
program?

In the latter cases, your options are slightly more abundant:
someone in an earlier reply mentioned the troubles of mapping
C datatypes to Ruby, which admittedly is a bit of a pain,
particularly when dealing with arrays and such (easier than
Python still, though, from what my repression allows me to
remember). As long as the main manipulation of the data structures
happens in C, the following would apply:

Instead of actually mapping the datatypes to Ruby, you can simply
wrap them inside opaque Ruby objects and pass them around that way.
Say you've defined a Ruby class 'MyData' (which in Ruby C is a
variable, traditionally c_MyData):

// You'd normally call this in your C code
extern void do_something(struct whatever * ptr);

#include 'ruby.h'

// VALUE is the basic Ruby type in C
VALUE make_opaque_wrapper(struct whatever * ptr) {
  // See 'Programming Ruby'
  VALUE wrapper = Data_Wrap_Struct(c_MyData, 0, 0, ptr);
  return wrapper;
}

// Wrapper function to access the normal C functions again
void access_do_something(VALUE wrapper) {
  // Extract the C structure
  struct whatever * ptr = 0;
  Data_Get_Struct(wrapper, struct whatever, ptr);
  // Call the C function
  do_something(ptr);
  return;
}

And so on. You'll want to read the links to Programming Ruby
given earlier.

This way your Ruby interface can be pretty much anything you
need. If you need to use values from those data structures *in*
Ruby (for manipulation or whatever), you can just write extraction
functions to be called at those times.

E