From: Stefano Crocco Date: 2007-01-25T01:55:06+09:00 Subject: Re: ebedded: calling a C function from script. Alle 17:00, mercoled� 24 gennaio 2007, Shea Martin ha scritto: > Here is another one i can't find in the book or online: > > How do I call a global function (which resides in a script) from C. > > > > > ruby_init(); > ruby_script("embedded"); > > init_my_ruby_stuff(); > > rb_load_file( "test.rb" ) > ID id = rb_intern( "script_main" ); > rb_funcall( rb_cObject, id, 0 ); > > ruby_finalize(); > > return 0; > > > But this crashes with an access violation when I run it... am I doing > something wrong? > > ~S Your problem is that you're calling 'script_main', which is an instance method of class object, as if it were a class method of Object. To do this, you should access the top level object. I've tried to find the correct method to do this, in vain. The best suggestion is this VALUE top_level=rb_eval_string("self"); rb_funcall(self, rb_intern("script_main"),0); As I said, there should be a better way, but this should work. Stefano