From: Friedrich Dominicus Date: 2003-02-28T23:23:38+09:00 Subject: Re: I'm stuck ts writes: > >>>>> "F" == Friedrich Dominicus writes: > > F> int main (void){ > F> int i; > F> VALUE obj; > F> VALUE klass; > F> ruby_init(); /* embed Ruby into this program! */ > > /* At this step you are playing a dangerous game with the GC */ what you you mean which this step ? ruby_init? How should I know what else to set up or use? > > F> /* uby_script("embed"); > F> rb_load_file("t1.rb"); */ > F> obj = rb_eval_string("load 't1.rb'"); > > > ruby_init_loadpath(); /* initialize search path */ > rb_require("t1"); /* no need for eval */ > > F> /* question why does rb_load_file does not work? */ > F> klass = rb_const_get(rb_cObject, rb_intern("T1")); > F> /* why does this work? Well my understanding ist that I loaded > F> the file into the embedded ruby, after that T1 is known, so I can look > F> it up. The problem I now is why rb_load_file does not work the same > F> way */ > > /* test if @@some_var is defined before trying to access it */ > > F> obj = rb_cv_get(klass, "@@some_var"); > > /* test here if obj is really an Array */ > > F> for (i = 0; i < RARRAY(obj)->len; ++i){ > F> printf("obj[%d] = %s\n", i, STR2CSTR(rb_ary_entry(obj,i))); > F> } > F> return 0; > F> } > > If ruby give an error, you'll have a segfault : none of your calls are > protected. Thanks I'll rewrite my stuff. I just wonder how you learned the usage, as told before I have searched a lot if messages, but did not found something that shows this... Regards Friedrich