Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > novice ruby embed question

Reply
Thread Tools

novice ruby embed question

 
 
Bill Kelly
Guest
Posts: n/a
 
      06-09-2004
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





 
Reply With Quote
 
 
 
 
nobu.nokada@softhome.net
Guest
Posts: n/a
 
      06-10-2004
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


 
Reply With Quote
 
 
 
 
Bill Kelly
Guest
Posts: n/a
 
      06-10-2004
Hi Nobu,

From: <(E-Mail Removed)>
> > 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




 
Reply With Quote
 
nobu.nokada@softhome.net
Guest
Posts: n/a
 
      06-10-2004
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Novice in Ruby Marcos José Setim Ruby 1 01-27-2006 01:31 PM
My Thought on the "Pickaxe book" (from a Ruby novice) John Maclean Ruby 35 01-24-2006 08:09 PM
embed ruby in windows c++ spam@mol.mn Ruby 1 02-10-2005 06:47 AM
Novice Question: Getting "bad file descriptor error" when trying to use gets in ruby 1.8.1 for windows Revision17 Ruby 4 02-14-2004 12:09 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments