# Ruby2c?

**URL:** <https://www.ruby-forum.com/t/ruby2c/169312>\
**Category:** Ruby\
**Created:** [June 2, 2009, 6:45am UTC](https://www.ruby-forum.com/t/ruby2c/169312 "2009-06-02T06:45:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [June 2, 2009, 6:45am UTC](https://www.ruby-forum.com/t/ruby2c/169312/1 "2009-06-02T06:45:06Z")

</div>

I tried to get ruby2c working recently and none of the files in the  
demos folder seem to translate, and requiring ruby\_to\_ansi\_c file  
doesn’t seem to work, either.

Anybody gotten this bad boy to work?

-=r

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [June 3, 2009, 6:29am UTC](https://www.ruby-forum.com/t/ruby2c/169312/2 "2009-06-03T06:29:21Z")

</div>

I tried to get ruby2c working recently and none of the files in the

> demos folder seem to translate, and requiring ruby\_to\_ansi\_c file  
> doesn’t seem to work, either.
> 
> Anybody gotten this bad boy to work?

Anyone know of any libraries out that convert bottlenecks in ruby to C?  
Or anything working that’s ruby to c?  
Thanks!  
-=r

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [June 3, 2009, 6:29pm UTC](https://www.ruby-forum.com/t/ruby2c/169312/3 "2009-06-03T18:29:18Z")

</div>

I did eventually get it working once, but I forget how I did it (and  
that box is gone now, so I can’t easily look it up). I also got  
ruby2cext working, which was a lot easier. For what I wanted, ruby2c  
wasn’t worth the headache.

I recall two things about ruby2c though:

1. it translates the ruby in your code to C, but not any included code  
or libs. At least that’s all it did for me. The end result was I  
could only translate rather simple methods, or small pieces of code to  
C, not whole programs.
2. it only worked in 1.8.x

ruby2cext ([http://ruby2cext.rubyforge.org/](http://ruby2cext.rubyforge.org/)) was fairly easy to get  
going, even with rather complex programs/libraries. The resulting  
code has to be run in ruby (just load it as a library I think…), but  
it worked pretty well.

–Kyle

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [June 6, 2009, 8:53pm UTC](https://www.ruby-forum.com/t/ruby2c/169312/4 "2009-06-06T20:53:53Z")

</div>

> I recall two things about ruby2c though:
> 
> 1. it translates the ruby in your code to C, but not any included code  
> or libs. At least that’s all it did for me. The end result was I  
> could only translate rather simple methods, or small pieces of code to  
> C, not whole programs.
> 2. it only worked in 1.8.x

I did see some recent github commits to try and bring it up to 1.9  
workability, but until I can actually get it to run…dunno.

> ruby2cext ([http://ruby2cext.rubyforge.org/](http://ruby2cext.rubyforge.org/)) was fairly easy to get  
> going, even with rather complex programs/libraries. The resulting  
> code has to be run in ruby (just load it as a library I think…), but  
> it worked pretty well.

Wow ruby2cext looks fascinating. It can even inline calls to core  
classes, like  
def go  
“”.center 3  
end

gets translated to ruby C  
VALUE go\_c(VALUE self) {  
return  
(\*(string\_center\_which\_we\_already\_looked\_up\_at\_load\_time))(NUM2INT(3));  
}

i.e. it avoids unnecessary function calls (if you pass it -O  
builtin\_methods).  
Thanks!  
-=r
