novice ruby embed question

B

Bill Kelly

Hi,

I'm just getting started embedding ruby, have set up
my main() as follows: (ala Pickaxe p.187, Embedding a
Ruby Interpreter.)

{
#ifdef _WIN32
// ruby win32 init
NtInitialize(&argc, &argv);
#endif

ruby_init();
ruby_script("embedded");

rb_load_file("test.rb");

ruby_run();
}

This seems work if rb_load_file() succeeds... But if
rb_load_file() fails to find the file, and tries to
raise an exception, the longjmp() is crashing.

I'm wondering if I'd be better off replacing the
rb_load_file() and ruby_run() with a call to
rb_eval_string("load test.rb") or some such?
(rb_eval_string_protect ??)

What I'd really like is to have ruby load and execute
a particular ruby file ("test.rb"), and then not call exit()
afterward. (But also not crash if file not found.)


Thanks for your help !

Regards,

Bill
 
N

nobu.nokada

Hi,

At Wed, 9 Jun 2004 17:26:08 +0900,
Bill Kelly wrote in [ruby-talk:102909]:
{ int status;
#ifdef _WIN32
// ruby win32 init
NtInitialize(&argc, &argv);
#endif

ruby_init();
ruby_script("embedded");
rb_load_protect(rb_str_new2("test.rb"), 0, &status);
if (status == 0) {
ruby_run();
}
 
B

Bill Kelly

Hi Nobu,

From: said:
rb_load_protect(rb_str_new2("test.rb"), 0, &status);
if (status == 0) {
ruby_run();
}

Thanks !!!

I'd also like ruby not to call exit() as ruby_run() does,
when it's finished. Is it safe for me to just call
ruby_exec(), like:

rb_load_protect(rb_str_new2("test.rb"), 0, &status);
if (status == 0) {
int state;
state = ruby_exec();
}

...instead of ruby_run()? Is there a better way?


Thanks!

Regards,

Bill
 
N

nobu.nokada

Hi,

At Thu, 10 Jun 2004 12:57:43 +0900,
Bill Kelly wrote in [ruby-talk:103030]:
I'd also like ruby not to call exit() as ruby_run() does,
when it's finished. Is it safe for me to just call
ruby_exec(), like:

rb_load_protect(rb_str_new2("test.rb"), 0, &status);
if (status == 0) {
int state;
state = ruby_exec();
}

...instead of ruby_run()? Is there a better way?

Yes, it got provided for the sake of that usage.
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top