[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Bare-bones Ruby

Leiradella, Andre V Matos Da Cunha

12/27/2004 6:33:00 PM

Hi All,

This is my first submission to the ruby-talk list. I've been using Lua
(http://w...) for some years now for some pet projects, which include
FullMoon (http://www.geocities.com/andre_leiradella...), a plugin for
the 3D modeler Moray that enables the authoring of other plugins in Lua.
Plugins in FullMoon probably exist in higher number than those written in
C/C++.

I've been fighting with Lua to make it look like the object plugins are
classes because Lua is not OO. Using a facility called metamethods, one can
create an OO-like environment, but some things get just too confused to use
like static class properties and calling inherited methods. I want OO
because I want to enable plugin writers to extend other objects with ease
and because I want to create a GUI for the plugins.

I've been looking for a script language that could be used in Lua's place
for FullMoon and I found Ruby. I downloaded it (3.4MB!) and I saw that it
comes with a great set of modules. So my first questions to the list are:

1) Is it possible to build Ruby without those modules? How?
2) How do I embed Ruby in a host program?
3) What are the functions that must be called to make Ruby load a program,
to create an instance of a class defined in Ruby, to call methods with this
instance etc.? Is this API documented somewhere?
4) Does Ruby support multiple inheritance or something similar to Java's
interfaces?

Best regards,

Andre de Leiradella


5 Answers

Edgardo Hames

12/27/2004 6:43:00 PM

0

On Tue, 28 Dec 2004 03:33:23 +0900, Leiradella, Andre V Matos Da Cunha
<ANDRE.LEIRADELLA@bra.xerox.com> wrote:
> Hi All,
>
> 4) Does Ruby support multiple inheritance or something similar to Java's
> interfaces?
>

Ruby does not support multiple inheritance but provides a very neat
way to reuse code: modules. Declaring a module and including it
automatically makes all the methods available in your classes.

Take a look at this:
http://www.rubycentral.com/book/tut_mo...

Kind Regards,
Ed
--
Pretty women make us buy beer, ugly women make us drink beer


Jeffrey Moss

12/27/2004 6:59:00 PM

0

There is an informative section on the Programming Ruby online book:

http://www.rubycentral.com/book/ext...

Should be a good introduction to embedding the interpreter in your C
program. It appears to do everything you're looking for.

Not clear what you mean by "modules", most modules dont have to be built, so
if you dont want them just delete the "lib" directory.

-Jeff

----- Original Message -----
From: "Leiradella, Andre V Matos Da Cunha" <ANDRE.LEIRADELLA@bra.xerox.com>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Monday, December 27, 2004 11:33 AM
Subject: Bare-bones Ruby


> Hi All,
>
> This is my first submission to the ruby-talk list. I've been using Lua
> (http://w...) for some years now for some pet projects, which
> include
> FullMoon (http://www.geocities.com/andre_leiradella...), a plugin
> for
> the 3D modeler Moray that enables the authoring of other plugins in Lua.
> Plugins in FullMoon probably exist in higher number than those written in
> C/C++.
>
> I've been fighting with Lua to make it look like the object plugins are
> classes because Lua is not OO. Using a facility called metamethods, one
> can
> create an OO-like environment, but some things get just too confused to
> use
> like static class properties and calling inherited methods. I want OO
> because I want to enable plugin writers to extend other objects with ease
> and because I want to create a GUI for the plugins.
>
> I've been looking for a script language that could be used in Lua's place
> for FullMoon and I found Ruby. I downloaded it (3.4MB!) and I saw that it
> comes with a great set of modules. So my first questions to the list are:
>
> 1) Is it possible to build Ruby without those modules? How?
> 2) How do I embed Ruby in a host program?
> 3) What are the functions that must be called to make Ruby load a program,
> to create an instance of a class defined in Ruby, to call methods with
> this
> instance etc.? Is this API documented somewhere?
> 4) Does Ruby support multiple inheritance or something similar to Java's
> interfaces?
>
> Best regards,
>
> Andre de Leiradella
>



Gennady

12/27/2004 6:59:00 PM

0

Get yourself a copy of "Programming Ruby" (Pickaxe) by Dave Thomas and
you find the answers for ALL your questions. And you will enjoy reading
it too ;-)

>
> 1) Is it possible to build Ruby without those modules? How?

After you build ruby you can use just a ruby executable without the
standard library if you do not need the functionality it provides. As
for built-in classes and modules, such as String, you will not be able
to get without them as they are implemented internally in C and other
parts of Ruby depend on them heavily.

> 2) How do I embed Ruby in a host program?

The book I mentioned has a very good chapter on embedding Ruby.

> 3) What are the functions that must be called to make Ruby load a
> program,
> to create an instance of a class defined in Ruby, to call methods with
> this
> instance etc.? Is this API documented somewhere?

I did not quite get the question, but if you mean the API between Ruby
and extensions written in C, Pickaxe discusses it in great details too.

> 4) Does Ruby support multiple inheritance or something similar to
> Java's
> interfaces?

Ruby has mix-ins, implemented with modules. As for Java-like
interfaces, you can easily do without them in Ruby, as Ruby uses so
called duck-typing (see Pickaxe for details).

>
> Best regards,
>
> Andre de Leiradella
>
>

Sincerely,
Gennady Bystritsky



gabriele renzi

12/27/2004 8:19:00 PM

0

Leiradella, Andre V Matos Da Cunha ha scritto:


> I've been looking for a script language that could be used in Lua's place
> for FullMoon and I found Ruby. I downloaded it (3.4MB!) and I saw that it
> comes with a great set of modules. So my first questions to the list are:
>
> 1) Is it possible to build Ruby without those modules? How?

most of the modules are pure ruby extensions or C extensions that can be
loaded at runtime, not basicly needed. But ruby has more things builtin
that Lua, I think (i.e. sockets are C extensions, SOAP is a ruby one,
Array and Hash are builtins)

> 2) How do I embed Ruby in a host program?

There is the "programming ruby" documentation, but you may find usefule
this pages:
http://metaeditor.sourceforge....
http://www.rubygarden.org/ruby...

> 3) What are the functions that must be called to make Ruby load a program,
> to create an instance of a class defined in Ruby, to call methods with this
> instance etc.? Is this API documented somewhere?

README.ext in the source distribution, I think.

> 4) Does Ruby support multiple inheritance or something similar to Java's
> interfaces?

modules can be mixed in to fit for 99% of good uses of multiple
inheritance, and callbacks like Module#included or Class#inherited can
be used to simulate interfaces a-la java (if you look on the ruby
application archive, raa.ruby-lang.org, you may find some pure ruby
interface system implementations)

Robert Klemme

12/28/2004 10:51:00 AM

0


"Jeffrey Moss" <jeff@opendbms.com> schrieb im Newsbeitrag
news:002301c4ec46$14eb0930$2c02a8c0@hans...
> There is an informative section on the Programming Ruby online book:
>
> http://www.rubycentral.com/book/ext...

For easier reference and less scrolling: "Embedding a Ruby Interpreter" is
located here:
http://www.rubycentral.com/book/ext...#S6

Kind regards

robert


>
> Should be a good introduction to embedding the interpreter in your C
> program. It appears to do everything you're looking for.
>
> Not clear what you mean by "modules", most modules dont have to be
built, so
> if you dont want them just delete the "lib" directory.
>
> -Jeff
>
> ----- Original Message -----
> From: "Leiradella, Andre V Matos Da Cunha"
<ANDRE.LEIRADELLA@bra.xerox.com>
> To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
> Sent: Monday, December 27, 2004 11:33 AM
> Subject: Bare-bones Ruby
>
>
> > Hi All,
> >
> > This is my first submission to the ruby-talk list. I've been using Lua
> > (http://w...) for some years now for some pet projects, which
> > include
> > FullMoon (http://www.geocities.com/andre_leiradella...), a
plugin
> > for
> > the 3D modeler Moray that enables the authoring of other plugins in
Lua.
> > Plugins in FullMoon probably exist in higher number than those written
in
> > C/C++.
> >
> > I've been fighting with Lua to make it look like the object plugins
are
> > classes because Lua is not OO. Using a facility called metamethods,
one
> > can
> > create an OO-like environment, but some things get just too confused
to
> > use
> > like static class properties and calling inherited methods. I want OO
> > because I want to enable plugin writers to extend other objects with
ease
> > and because I want to create a GUI for the plugins.
> >
> > I've been looking for a script language that could be used in Lua's
place
> > for FullMoon and I found Ruby. I downloaded it (3.4MB!) and I saw that
it
> > comes with a great set of modules. So my first questions to the list
are:
> >
> > 1) Is it possible to build Ruby without those modules? How?
> > 2) How do I embed Ruby in a host program?
> > 3) What are the functions that must be called to make Ruby load a
program,
> > to create an instance of a class defined in Ruby, to call methods with
> > this
> > instance etc.? Is this API documented somewhere?
> > 4) Does Ruby support multiple inheritance or something similar to
Java's
> > interfaces?
> >
> > Best regards,
> >
> > Andre de Leiradella
> >
>
>
>