Hello!
I am trying to create a new Ruby extension, which eventually will
give to Ruby the functionality of a C++ project.
So far, the extension is going fine. However I have two issues:
(1) C++ Type Casting
(2) Multiple Inheritance
Is there a generic approach to solve the above?
As far as C++ Type Casting is concerned I am thinking of creating
to_xxx methods. I.e.
foo = (Foo *) Bar->dump();
will be in Ruby:
foo = Bar.dump.as_Foo
As far as Multiple Inheritence is concerned, I think the only way
to go through is to define modules and include them in other modules.
Howver the C++ project I’m trying to create Ruby Bindings for, has a very
complex inheritence tree. Is there any other workaround?
Regards,
···
–
University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky
I haven’t checked the specifics, but have you read Lyle’s talk
from the 2002 Rubyconf?
Ruby | zenspider.com | by ryan davis
···
On Sunday, 23 November 2003 at 17:44:39 +0900, Elias Athanasopoulos wrote:
Hello!
I am trying to create a new Ruby extension, which eventually will
give to Ruby the functionality of a C++ project.
So far, the extension is going fine. However I have two issues:
(1) C++ Type Casting
(2) Multiple Inheritance
–
Jim Freeze
Klein bottle for sale … inquire within.
As far as C++ Type Casting is concerned I am thinking of creating
to_xxx methods. I.e.
foo = (Foo *) Bar->dump();
This is not C++ type casting; this is a C-style cast. In C++, you
generally want to avoid C-style casts because C-style casts are far too
powerful (they let you lie to the compiler far too easily). Please
consider using static_cast<> and dynamic_cast<> whenever possible.
will be in Ruby:
foo = Bar.dump.as_Foo
I’m not sure this really applies well to Ruby. Because Ruby is
dynamically typed, there’s no reason why dump() can’t just return an
object of the appropriate type (e.g. return a Foo if you really have a
Foo or return a Bar if you really have a Bar).
As far as Multiple Inheritence is concerned, I think the only way
to go through is to define modules and include them in other modules.
Howver the C++ project I’m trying to create Ruby Bindings for, has a very
complex inheritence tree. Is there any other workaround?
Yes, modules are the way to go. See [ruby-talk:66580] and my suggestion
in [ruby-talk:66624].
Paul
···
On Sun, Nov 23, 2003 at 05:44:39PM +0900, Elias Athanasopoulos wrote:
Thanks for all the replies in my question. I was to busy to answer.
My apologies for the delay.
Regards,
···
On Thu, Nov 27, 2003 at 06:21:54AM +0900, Paul Brannan wrote:
On Sun, Nov 23, 2003 at 05:44:39PM +0900, Elias Athanasopoulos wrote:
As far as C++ Type Casting is concerned I am thinking of creating
to_xxx methods. I.e.
foo = (Foo *) Bar->dump();
This is not C++ type casting; this is a C-style cast. In C++, you
generally want to avoid C-style casts because C-style casts are far too
powerful (they let you lie to the compiler far too easily). Please
consider using static_cast<> and dynamic_cast<> whenever possible.
–
University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky