novice ruby embed question

Discussion in 'Ruby' started by Bill Kelly, Jun 9, 2004.

  1. Bill Kelly

    Bill Kelly Guest

    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
     
    Bill Kelly, Jun 9, 2004
    #1
    1. Advertising

  2. Bill Kelly

    Guest

    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
     
    , Jun 10, 2004
    #2
    1. Advertising

  3. Bill Kelly

    Bill Kelly Guest

    Hi Nobu,

    From: <>
    > > 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
     
    Bill Kelly, Jun 10, 2004
    #3
  4. Bill Kelly

    Guest

    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
     
    , Jun 10, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ra

    VHDL novice question

    ra, Jul 13, 2004, in forum: VHDL
    Replies:
    6
    Views:
    2,919
    Allan Herriman
    Jul 13, 2004
  2. sean
    Replies:
    1
    Views:
    621
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  3. Revision17
    Replies:
    4
    Views:
    276
    Shashank Date
    Feb 14, 2004
  4. John Maclean
    Replies:
    35
    Views:
    336
    Donkey Agony
    Jan 24, 2006
  5. Marcos José Setim

    Novice in Ruby

    Marcos José Setim, Jan 27, 2006, in forum: Ruby
    Replies:
    1
    Views:
    92
    Tassilo Horn
    Jan 27, 2006
Loading...

Share This Page