Latest info on embedding Ruby in a C++ app
- From: "Timothy Byrd" <byrd.timothy@xxxxxxxxx>
- Date: 30 Aug 2005 17:10:10 -0700
I'm looking for info on calling multiple Ruby scripts from inside a C++
application. Is there anything like a definitive document about doing
this?
So far, I've googled the web and comp.lang.ruby, and I've looked at the
Pragmatic Guide.
As a test, I have:
int main(int argc, char** argv)
{
#ifdef WIN32
NtInitialize(&argc, &argv);
#endif
ruby_init();
ruby_script("embedded");
char* filename = 0;
int status = 0;
for (int i = 0; i < 3; ++i)
{
// [snip] do something to put the script path
// into filename for this iteration.
// rb_load_protect(rb_str_new2(filename), 0, &status);
rb_load_file(filename);
// if (status == 0)
// {
// [snip] set command arguments
// and call ruby_set_argv()
status = ruby_exec();
// }
}
ruby_cleanup(status);
return 0;
}
I know I need to wrap things in rb_protect() to save me from Ruby
crashing the whole application. Are there any gotchas here?
How do I get the value of Kernel::exit once a Ruby script finishes?
ruby_exec() seems to only return 0 or 6.
If I am executing multiple scripts, should I just call ruby_init() once
at the beginning and ruby_cleanup() once at the end?
Thanks,
-- Timothy
.
- Follow-Ups:
- Prev by Date: Re: Fwd: [SOLUTION] Word Chains (#44)
- Next by Date: Re: Ruby on Linux & Windows
- Previous by thread: Ruby on Linux & Windows
- Next by thread: Re: Latest info on embedding Ruby in a C++ app
- Index(es):