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

Heesob Park phasis at gmail.com
Sat Feb 2 20:24:22 EST 2008


Hi,

2008/2/3, Daniel Berger <djberg96 at gmail.com>:
>
> 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?


I don't know anything about mixin programming with C++.
But some googling will help you like this.
Mixin-Based Programming in C++(http://www.ddj.com/cpp/184404445)

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);
> }


It looks good up to now.


Regards,

Park Heesob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/win32utils-devel/attachments/20080203/e7f6c812/attachment.html 


More information about the win32utils-devel mailing list