Skip navigation.

Sign up | Lost password? | Help

Embedding Ruby in C Programs

1. ruby_test1.c
#include <ruby.h>

int main(int argc, char *argv[])
{
 ruby_init();
 rb_eval_string("puts 'hello world'");
 ruby_finalize();
 return 0;
}

2. ruby_test2.c
#include <ruby.h>

int main(int argc, char *argv[])
{
 ruby_init();
 ruby_init_loadpath();
 rb_load_file("script.rb");
 ruby_exec();
 //ruby_run();
 //ruby_finalize();
 return 0;
}

3. compile in debian with g++
g++ -o ruby_test1 ruby_test1.c -I/usr/lib/ruby/1.8/i486-linux/ -lruby1.8
g++ -o ruby_test2 ruby_test2.c -I/usr/lib/ruby/1.8/i486-linux/ -lruby1.8


4. Links
Embedding Ruby in C++
Ruby C Language API
ruby embedded into c++

Linux.Conf.Au 2008Perfect Graph

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies