From: nobu.nokada@... Date: 2003-02-07T11:39:47+09:00 Subject: Re: Embedding Ruby in C code Hi, At Thu, 6 Feb 2003 18:50:18 +0900, Szymon Drejewicz wrote: > How to execute Ruby script without ruby_run() after rb_load_file() > command? I'm going to run some Ruby script many times in one C > application, but direct reading ruby file and passing it to > rb_eval_string() is not comfortable. In other hand ruby_run() calls > exit(). Maybe there is some way to launch script not by using > ruby_run(). 1.8 has ruby_exec() and ruby_cleanup(), but none in 1.6. ruby_exec() executes loaded AST and returns tag status. Following example loads "embedded.rb" and runs it thrice. #include "ruby.h" int main(int argc, char **argv) { int status; ruby_init(); ruby_script(argv[0]); ruby_init_loadpath(); rb_protect((VALUE (*)())rb_load_file, (VALUE)"embedded.rb", &status); if (status == 0) { int i; for (i = 0; i < 3; i++) if ((status = ruby_exec()) != 0) break; } return ruby_cleanup(status); } -- Nobu Nakada