I have a problem with embedding Ruby, which hopefully someone can shed some
light on…
Basically, I don’t want to just load some code and then ruby_run() it. I
want to choose at run-time some modules to load with rb_require, then create
instances of objects, and send messages to those objects. There is no ‘main
ruby program’ as such.
It seems to work, but the problem is that untrapped exceptions cause a SEGV
and a core dump. Another problem is that $: is set to an empty array. It
looks like I’m missing some initialisation function or functions.
I have grepped the source and found “ruby_init_loadpath” to set $:, but is
there something else I need to call to fix the SEGV problem?
Thanks,
Brian.
$ cat embed.c
#include <stdio.h>
#include <ruby.h>
int main(void)
{
printf(“Starting\n”);
ruby_init();
ruby_script(“embed”);
rb_require("/nonexistent/file");
#if RUBY_VERSION_CODE >= 180
rb_cleanup(0);
#endif
printf(“Done\n”);
return 0;
}
$ gcc -Wall -g -o embed embed.c -lruby -lcrypt -lm -I /usr/local/lib/ruby/1.6/i386-freebsd4.7 -L /usr/local/lib/ruby/1.6/i386-freebsd4.7
$ ./embed
Starting
embed: No such file to load – /nonexistent/file (LoadError)
embed: [BUG] Segmentation fault
ruby 1.6.8 (2002-12-24) [i386-freebsd4.7]
Abort trap (core dumped)
$ gcc -Wall -g -o embed embed.c -lruby-static -lcrypt -lm -I /usr/local/lib/ruby/1.8/i386-freebsd4.7 -L /usr/local/lib
$ ./embed
Starting
embed: No such file to load – /nonexistent/file (LoadError)
embed: [BUG] Segmentation fault
ruby 1.8.0 (2003-06-23) [i386-freebsd4.7]
Abort trap (core dumped)
*** NOTE ***
Changing the rb_require to
rb_eval_string(“require ‘/nonexistent/file’”);
still generates the SEGV and core dump