From: Chris Pine Date: 2001-02-01T06:48:34+09:00 Subject: [ruby-talk:10194] Re: Embedded Ruby problems ----- Original Message ----- From: "Olivier CARRERE" Hi, I'm trying to embed Ruby into another C++ program, and I'm facing two problems: 1. I'm not sure of what is the sequence to run to start the interpreter, I tried this one with no success : ruby_init(); ruby_script("foo.rb"); // foo.rb only makes a print "hello" ruby_run(); // The program stops while calling it without even printing the 'hello' string 2. The worst problem is that the called script interpreter makes and exit() to stop, wich has the disastrous consequence of stopping my calling program! Is there a function to stop cleanly the ruby interpreter so that I can replace each exit() into ruby's source code and continue my program after a ruby_run() call? Thanks for any clue, - Olivier CARRERE --------------------------------- This has been by experience as well. The 'exit()' calls in particular are frustrating. It appears to me that the Ruby Interpreter code was made only for use in the compiled Ruby Interpreter (and not for embedded applications). Only embedded Ruby would be feasable for my professional use (though I love it for personal use), but embedded Ruby doesn't do what I want it to. Ideally, I would like to init ruby, then run a '.rb' file. (Maybe that file just has a few class definitions.) Then I'm back in my program, where I create a Ruby class in C, and maybe a global Ruby variable in C. Then my program does its thing for a while, until I need to use my Ruby stuff, so I load up another Ruby file and run it. (Let's say it creates instances of the Ruby classes in the first Ruby file and the ones I made in C, then computes something and stores a value in the global variable.) I read the value of the global variable in C(++) and continue right along... Ah, but it just doesn't work that way. It looks to me like Ruby was made to be the "outside" language, with possible pockets of C inside. As far as I can see, embedded Ruby means "you can have a C program start your Ruby program, but then that's it"... Unless I missed something... Chris Pine