[Win32utils-devel] Ruby++ FFI (theoretical)

Daniel Berger djberg96 at gmail.com
Sat Feb 2 12:29:45 EST 2008


Hi all,

How does this look as a potential FFI for our theoretical Ruby++ ?

I'm not sure how to do mixins, though. Some sort of special directive? 
Or just add it to inheritance chain?

Anyway, this is just a rough prototype. No attempt at an actual 
implementation yet.

Regards,

Dan

// foo.h - Function prototypes
#define _FOO_H_
using namespace ruby;

// Subclass Object
class Foo : public RubyObject {
    public:

       // Constructor and Destructor
       Foo();  // constructor
       ~Foo(); // destructor

       // Instance Methods
       VALUE method_a();
       VALUE method_b(VALUE);

       // Singleton Methods
       static VALUE method_c(VALUE);
};

// foo.cpp - Implementation
#include <iostream>
#include <foo.h>
using namespace ruby;

/* Constructor */
Foo::Foo(){
    cout << "Hello Worldn";
}

/* Or maybe we setup some sort of default Object destructor instead
  * of making people do it explicitly, unless they have special 
requirements.
  */
Foo::~Foo(){
    delete this;
}

VALUE Foo::method_a(){
    return ruby_int(27);
}

VALUE Foo::method_b(VALUE av_name){
    return "hello, " << ruby_name;
}

static VALUE(VALUE av_age){
    return av_age + ruby_int(42);
}


More information about the win32utils-devel mailing list