On Tuesday 16 August 2005 19:01, Shalev NessAiver wrote:
> Forgive my newbness, but how would one use/compile that code?
> The instructions for creating an extension (using extconf.rb) seems  
> to be geared towards
> compiling Ruby-C classes... how I just compile and run this code?

For me, under linux, it was:

gcc -I /usr/lib/ruby/1.8/i686-linux -lm -ldl -lcrypt -lruby -o repl repl.c

If you're not a C programmer that's "compile, look for headers 
in /usr/lib/ruby/1.8/i686-linux (that's where ruby.h lives), dynamically 
link against the math (m), dl, crypt, and ruby libraries, name the output 
file 'repl' and use repl.c as the source file."

If you want to distribute it to another system that might not have Ruby 
installed, you can also statically link against Ruby:

gcc -I /usr/lib/ruby/1.8/i686-linux -lm -ldl -lcrypt -o repl 
repl.c /usr/lib/libruby18-static.a

The one thing to be aware of is that, unlike IRB, this one is single-line 
only, so to define a function you'd have to do:

repl> def foo; puts "Foo!"; end

if you just type "def foo" and hit enter, it will decide it's a syntax 
error.  I guess the real "IRB" interpretation is able to distinguish 
between syntax errors and incomplete entry?  I dunno.

Ben