Novice ruby embed question

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

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();
      }

···

}

--
Nobu Nakada

Hi Nobu,

> ruby_init();
> ruby_script("embedded");
>
      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

···

From: <nobu.nokada@softhome.net>

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.

···

--
Nobu Nakada