Post by Peter Cooper on August 1st, 2006
How to create a Ruby extension in C in 43 seconds

- Write C code inline with your Ruby code
- Using RubyInline to Speed Up Code By 10x
- ParseTree 2.0.0 Released


Less than two months ago, I wrote How to Create a Ruby Extension in C in under 5 minutes. Times have changed.
Zenspider, the master of all things Ruby crossed with C, picked up the gauntlet and, using RubyInline (previously covered here), has handed my proverbial ass back to me on a platter. All you have to have is the RubyInline library installed.
In just 43 seconds, you too could launch an editor, paste in this code, and check it out:
#!/usr/local/bin/ruby -w require 'rubygems' require 'inline' class Example inline(:C) do |builder| builder.c "int test1() { int x = 10; return x; }" end end p Example.new.test1
No ruby.h? What ruby.h!? It's as easy as that.

Click here to add on del.icio.us
Tweet This








