C++ code into Ruby, I need it fast, no time for RTFM

L

Leslie Viljoen

Have you gotten a suitable answer yet?

There are several options for you here.
1) Transliterate into Ruby (as you imply)
2) Leave your code as-is and wrapper it using Ruby's C api
3) Leave your code as-is and use the Ruby DL module to load your
library and invoke the methods
4) Use the RubyInline module to simply "inline" your C/C++ code into a
Ruby program

Just tried RubyInline - amazing!
I had one GCC hiccough on my Ubuntu 6 system, I had to do this:

ln -s /usr/lib/gcc/x86_64-linux-gnu/4.0.3/cc1 /usr/bin/cc1plus

..to get GCC to recognise that G++ had been installed. Otherwise it
gave me this:
gcc: installation problem, cannot exec `cc1plus': No such file or directory
 
B

bpfurtado

Have you gotten a suitable answer yet?

There are several options for you here.
1) Transliterate into Ruby (as you imply)
2) Leave your code as-is and wrapper it using Ruby's C api
3) Leave your code as-is and use the Ruby DL module to load your
library and invoke the methods
4) Use the RubyInline module to simply "inline" your C/C++ code into a
Ruby program

By far the quickest solution is going to be the RubyInline route.
You'll need a compiler installed on your machine to handle the C++
code compilation step RubyInline performs. You can install RubyInline
via the gem command:

gem install -r rubyinline

Shoot a nice note of thanks off to Eric Hodel and Ryan Davis. They've
done a great job with that little gem.
Have fun learning Ruby! I've learned far more about programming by
using Ruby than I ever learned using C/C++ or Java.

You can´t blame C/C++ or Java or any programming language for your
learning skills.

--
"Minds are like parachutes, they work best when open."
"I know nothing except the fact of my ignorance."
Bruno Patini Furtado
Software Developer
text adventures suite: http://bpfurtado.net/tas
software development blog: http://bpfurtado.livejournal.com
Ruby related topics: http://bpfurtado.livejournal.com/tag/ruby
 
M

Michael T. Richter

--=-c3ue16HfnFPT2U/ldcCF
Content-Type: multipart/alternative; boundary="=-bMXNE6F4xDZ0GWghI4or"


--=-bMXNE6F4xDZ0GWghI4or
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

There are still ways to ask for things.


And those ways vary by culture. Andrei is painfully obviously not a
native English speaker. Cut the guy some slack. What happened to the
whole "Matz Is Nice So...." meme that supposedly dominates this
community?

--=20
Michael T. Richter <[email protected]> (GoogleTalk:
(e-mail address removed))
A well-designed and humane interface does not need to be split into
beginner and expert subsystems. (Jef Raskin)

--=-bMXNE6F4xDZ0GWghI4or
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; CHARSET=3DUTF-8">
<META NAME=3D"GENERATOR" CONTENT=3D"GtkHTML/3.12.1">
</HEAD>
<BODY>
On Wed, 2007-25-04 at 21:12 +0900, David Jones wrote:
<BLOCKQUOTE TYPE=3DCITE>
<PRE>
<FONT COLOR=3D"#000000">There are still ways to ask for things.</FONT>
</PRE>
</BLOCKQUOTE>
<BR>
And those ways vary by culture.&nbsp; Andrei is painfully obviously not a n=
ative English speaker.&nbsp; Cut the guy some slack.&nbsp; What happened to=
the whole &quot;Matz Is Nice So....&quot; meme that supposedly dominates t=
his community?<BR>
<BR>
<TABLE CELLSPACING=3D"0" CELLPADDING=3D"0" WIDTH=3D"100%">
<TR>
<TD>
-- <BR>
<B>Michael T. Richter</B> &lt;<A HREF=3D"mailto:[email protected]">ttmri=
(e-mail address removed)</A>&gt; (<B>GoogleTalk:</B> (e-mail address removed))<BR>
<I>A well-designed and humane interface does not need to be split into begi=
nner and expert subsystems. (Jef Raskin)</I>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

--=-bMXNE6F4xDZ0GWghI4or--

--=-c3ue16HfnFPT2U/ldcCF
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQBGMKjjLqyWkKVQ54QRAol2AJ4wJWOdt1uWIrHrItGS+g+Az1vZpwCgy72C
Q5IVklKUO1yaqydkhv6Jm5Y=
=GAws
-----END PGP SIGNATURE-----

--=-c3ue16HfnFPT2U/ldcCF--
 
A

Andrei Ursan

Thanks all of you for the links and support.
It's realy amazing and funny what you can do with Ruby.
 
T

Tim Pease

Just tried RubyInline - amazing!
I had one GCC hiccough on my Ubuntu 6 system, I had to do this:

ln -s /usr/lib/gcc/x86_64-linux-gnu/4.0.3/cc1 /usr/bin/cc1plus

..to get GCC to recognise that G++ had been installed. Otherwise it
gave me this:
gcc: installation problem, cannot exec `cc1plus': No such file or directory

The magic behind RubyInline is the rbconfig.rb file. This little Ruby
script contains the build environment used to compile the Ruby
interpreter for your particular platform. When RubyInline compiles
code, it uses the build environment found in rbconfig.rb.

So, the catch is that your machine environment
(compilers/libraries/etc) needs to agree with what is in rbconfig.rb.

For my Ruby/Cywin installation, rbconfig.rb can be found here ...

/usr/lib/ruby/1.8/i386-cygwin/rbconfig.rb

Blessings,
TwP
 
L

Leslie Viljoen

The magic behind RubyInline is the rbconfig.rb file. This little Ruby
script contains the build environment used to compile the Ruby
interpreter for your particular platform. When RubyInline compiles
code, it uses the build environment found in rbconfig.rb.

So, the catch is that your machine environment
(compilers/libraries/etc) needs to agree with what is in rbconfig.rb.

For my Ruby/Cywin installation, rbconfig.rb can be found here ...

/usr/lib/ruby/1.8/i386-cygwin/rbconfig.rb

Blessings,
TwP

Just installed the next Ubuntu, so I'll look at this. Thanks!


--=20
If you could create a machine that copies hamburgers =97 you put one
hamburger in and two equally good hamburgers come out the other side =97
it would be unethical not to do so and make it freely available.
 
L

Leslie Viljoen

Um, what do you mean by *that*? I have just one brain - am I old fashioned?

Alternative as in abnormal. I just mean that the book is highly
strange, for people who appreciate strange. I really enjoyed it
myself.

Ah the scarf eaters... so wistful.
 
L

Leslie Viljoen

Just installed the next Ubuntu, so I'll look at this. Thanks!

It just worked on Feisty, so they must have fixed the GCC installation.
Looked at rbconfig though. Thanks for the tip.

Les
 
D

Dan Zwell

Leslie said:
Alternative as in abnormal. I just mean that the book is highly
strange, for people who appreciate strange. I really enjoyed it
myself.

Ah the scarf eaters... so wistful.

I probably would have loved _why's book, except I was so impatient to
learn ruby that I skipped over all the non-technical parts. It was
pretty informative, but its strange beauty was lost on a student that
pretty much wanted to learn Ruby in one night.
 
R

Robert Dober

I agree, this mailing list seems to be getting a lot more hostile towards
people new to ruby. Posting a link to google or how to ask questions, or
making a snide remark about how they format their messages is not going to
get people into ruby. I know if someone just posted a link to google with
nothing else if I asked a question about a new language, I would be turned
off from it, even if I could have asked it better.
Hmm are you not exaggerating a bit?
I was *very* amused that OP got answers at all!
Personally I feel that this is still a great community and that this
community should not stretch to be more popular at any cost.
I had pretty much preferred to ignore that post but others decided,
very honorably, to tell OP to change his attitude if he wants to
obtain something.
I think that your statement "could have asked it better" is the
euphemism of the month ;).
Cheers
Robert
 
J

John Joyce

Hmm are you not exaggerating a bit?
I was *very* amused that OP got answers at all!
Personally I feel that this is still a great community and that this
community should not stretch to be more popular at any cost.
I had pretty much preferred to ignore that post but others decided,
very honorably, to tell OP to change his attitude if he wants to
obtain something.
I think that your statement "could have asked it better" is the
euphemism of the month ;).
Cheers
Robert
Not to harp on the issue, but had the same post gone to C or C++
mailing-list, it would've been flamed only with no solutions. The
beauty of the Ruby world is that (in the words of Masayoshi
Takahashi, of Ruby Kaigi) "Ruby is for lazy people" "java and c++ are
for diligent people". It means Ruby is fun and not painful like many
languages, so people actually enjoy responding to the list and trying
to make nice code!
The culture of those other languages tends to be the anal-retentive,
I'm-smarter-than-you, RTFM attitude.
In Ruby, RTFM is RTWFM, where W = wonderful. Unlike those other
languages, this stuff isn't terse and most of the books are good
ones. (Nothing is more annoying to me than being referred to K&R2,
one of the least accessible texts I've ever read, even though it does
have a wealth of good information in it.)
 
P

Philip Gatt

I'm a long time ruby user, but I just joined this list tonight. It's
disappointing to see drama already. I hope this is not the norm.

- Philip
 
L

Leslie Viljoen

I'm a long time ruby user, but I just joined this list tonight. It's
disappointing to see drama already. I hope this is not the norm.

- Philip

Everywhere where there are people together there will be conflict. On
the whole ruby-talk is the greatest forum I have been a part of.
"Drama" is extremely rare, mostly it's just a hundred questions a day
being answered with a thousand answers.

Also, some really great programmers regularly post here.
 
R

Robert Dober

I'm a long time ruby user, but I just joined this list tonight. It's
disappointing to see drama already. I hope this is not the norm.
Rare exception, search the archives a little bit if you have time, you
will see we are not lying to you, these things happen maybe 2 to 5
times a year...

Still I think this thread is not a problem and normally I am quite
sensible, but some folks are shocked and that is a pitty of course.

Welcome to the group!!

Cheers
Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top