From: Michael Neumann Date: 2008-01-09T01:53:26+09:00 Subject: Re: Embedding 1.9 Dave Thomas wrote: > Moved over from ruby-talk... > > > On Jan 7, 2008, at 9:36 PM, Yukihiro Matsumoto wrote: > >> You can load Ruby programs with rb_load(). > > In 1.9, though, is that enough, or do we then have to call > rb_iseq_new/eval to have the file's contents actually run (when I try > just rb_load_file, it gets compiled but the code in the file doesn't > appear to be actually executed). > > From an embedding point of view, this is slightly problematic, as > rb_load_file returns VOID *, so it's hard to pass the parse tree on. > > Should I perhaps be calling rb_load(rb_str_new2("file.rb", 0)? Dave, I had to do the following to get it working: /* * Forward declarations for Ruby */ void * rb_compile_cstr(const char *f, const char *s, int len, int line); int main() { RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); ruby_script("..."); ruby_run_node(rb_compile_cstr("yourfile", (const char*)"p :hello", /* strlen */ 8, /* line no */ 1)); } I also had to change some things in YAML/syck when I tried to link everything statically... but then no .so files work anymore. Regards, Michael