Ruby 1.9 - equivalent of ruby_run() ?

S

Suraj Kurapati

Hello,

In Ruby 1.8, I was able to start the Ruby interpreter using ruby_run():

char* file = "foobar.rb";
ruby_script(file);
rb_load_file(file);
ruby_run(); // start the interpreter

In Ruby 1.9, there is a ruby_run_node() function instead, but I have not
been able to use it successfully. I tried:

char* file = "foobar.rb";
ruby_script(file);
rb_load_file(file);
ruby_run_node(NULL); // start the interpreter

And I also tried:

char* file = "foobar.rb";
ruby_script(file);
rb_load_file(file);
ruby_run_node(ruby_options(0, NULL)); // start the interpreter

And I also tried:

char* argv[] = {"foobar.rb"};
ruby_run_node(ruby_options(1, argv)); // start the interpreter

None of these worked; the interpreter would immediately dump core.

What is the correct way to do this?

Thanks for your consideration.
 
S

Suraj Kurapati

Suraj said:
In Ruby 1.9, there is a ruby_run_node() function instead, but I have not
been able to use it successfully. I tried:

char* file = "foobar.rb";
ruby_script(file);
rb_load_file(file);
ruby_run_node(NULL); // start the interpreter

I hunted around in the Ruby 1.9.0 source code and found an example in
load.c. The solution is to pass the return value of rb_load_file() to
ruby_run_node():

char* file = "foobar.rb";
ruby_script(file);
void* node = rb_load_file(file);
ruby_run_node(node); // start the interpreter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top