From: ts Date: 2003-07-23T22:33:59+09:00 Subject: Re: Embedding problem - SEGV >>>>> "B" == Brian Candler writes: B> Do I really have to write each section as a separate C function, and call it B> under rb_protect? Something like this struct tt { char *cmd, *arg; }; static VALUE process_line(struct tt *tts) { VALUE obj = Qnil; if (!strcmp(tt->cmd, "loadLibrary")) rb_require(tt->arg); else if (!strcmp(tt->cmd, "loadObject")) { VALUE klass = rb_const_get(rb_cObject, rb_intern(tt->arg)); obj = rb_funcall(klass, rb_intern("new"), 0); } /* ... etc */ return obj; } int main(int argc, char **argv) { struct tt tts; int status; VALUE result; ruby_init(); ruby_init_loadpath(); tt.cmd = argv[1]; tt.arg = argv[2]; result = rb_protect(process_line, &tts, &status); if (status) { /* display an error message */ } else { /* do what you want with result */ } return 0; } The idea is to initialize ruby, then make all call to ruby functions in one (or more) function protected by rb_protect() Guy Decoux