On Wed, 1 May 2002, Edward Wilson wrote:
> 
> Now I'm getting a consistant and misterious exit whenever I call
> embeded ruby from within a C application running on Linux or a C++
> (compiled with V-Studio.NET) application running on XP-pro.
> 
> I Know I'm doing something wrong.  One should be able to run in a loop
> at the C/C++ level and call a ruby script and return to whatever they
> were doing in the top C/C++ layer.
> 
> Am I loading the wrong version of the interpreter, or do I need to
> seed the interpretor with some special value other than...
> 
> ruby_init();
> ruby_script("embeded");
> rb_load_file("hello.rb")//the ruby script I'm calling from C/C++
> 
> begin__C_loop
> //do some C/C++ work here
> ruby_run() //decide it's time to call ruby here
> //back to more C/C++ work here (--not getting to here--)
> end_C_loop
> 
You might try something like:

main(int argc, char **argv)
{
struct stat mystat;
char *myscript;

     fd = open("myscript.rb", "r");
// ignore errors for this example
     fstat(fd, &mystat);
     myscript = malloc(mystat.st_size);

     read(fd, myscript, mystat.st_size);
     ruby_init();

begin__C_loop
//do some C/C++ work here
rb_eval_string(myscript); //decide it's time to call ruby here
//back to more C/C++ work here (--not getting to here--)
end_C_loop
}

In other words, read your entire script into a large string, once at
the beginning of your program.  Then, whenever you need to do some
Ruby processing, call rb_eval_string to execute your script.

Good luck

Dennis