From: Brian Candler Date: 2008-10-29T20:58:22+09:00 Subject: Re: automatic code conversion from Ruby to C ? Axel Etzold wrote: > I was just wondering whether there'd be some tool that would translate > some of my Ruby > code into C/C++ to speed up the development process. If it did, at best it would generate something like this: /* str = "hello" str.upcase! */ VALUE str = rb_str_new2("hello"); rb_funcall(str, rb_intern("upcase!"), 0); That is, it would use entirely Ruby data structures, so the rest of your C code would have to be written to use Ruby data structures too. So it's nothing like hand-written C. See http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html#S2 > and there doesn't seem to be a > way of translating Ruby's Hashes to C What's a "C hash"? Perhaps you mean glib, or STL, or a zillion other possible C/C++ libraries? Ruby doesn't use any of these, and Ruby's hashes don't map directly to any of them (for example, coders can subclass Hash, or override methods in it; and a Ruby Hash can contain mixed types for both keys and values) Even simple things like "Integer" don't map directly to C. In Ruby, Integers are unbounded size, with automatic conversions from Fixnum to Bignum. So something simple like a = 0 loop { a = a + 1; puts a } is not the same as long a = 0; while(1) { a += 1; printf ("%ld\n", a); } -- Posted via http://www.ruby-forum.com/.