Initializing $LOAD_PATH manually? (embedding ruby)

D

Daniel Harple

Hi,

I am embedding ruby in an application and shipping it with app as
well, so I need to setup the load path manually instead of calling
ruby_init_loadpath(). Here is the code:

NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [NSString stringWithFormat:mad:"%@/../Resources/ruby",
[bundle pathForAuxiliaryExecutable:mad:"My App"]];
load_path = rb_ary_new();
rb_ary_push(load_path, rb_str_new2([[NSString stringWithFormat:mad:"%@/%
s", path, "site_ruby/1.8"] UTF8String]));
rb_ary_push(load_path, rb_str_new2([[NSString stringWithFormat:mad:"%@/%
s", path, "site_ruby/1.8/powerpc-darwin8.7.0"] UTF8String]));
rb_ary_push(load_path, rb_str_new2([[NSString stringWithFormat:mad:"%@/%
s", path, "site_ruby"] UTF8String]));
rb_ary_push(load_path, rb_str_new2([[NSString stringWithFormat:mad:"%@/%
s", path, "1.8"] UTF8String]));
rb_ary_push(load_path, rb_str_new2([[NSString stringWithFormat:mad:"%@/%
s", path, "1.8/powerpc-darwin8.7.0"] UTF8String]));
rb_gv_set("$:", load_path);

I get this error:

ruby: $: is a read-only variable (NameError)

How can I get around this?

Thanks,
-- Daniel
 
D

Daniel Harple

I get this error:

ruby: $: is a read-only variable (NameError)

How can I get around this?

Well, that was dumb of me. This worked:

NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [NSString stringWithFormat:mad:"%@/../Resources/ruby",
[bundle pathForAuxiliaryExecutable:mad:"My App"]];
VALUE load_path = rb_gv_get("$:");
rb_ary_push(load_path, rb_str_new2([[NSString stringWithFormat:mad:"%@/%
s", path, "site_ruby/1.8"] UTF8String]));
rb_ary_push(load_path, rb_str_new2([[NSString stringWithFormat:mad:"%@/%
s", path, "site_ruby/1.8/powerpc-darwin8.7.0"] UTF8String]));
rb_ary_push(load_path, rb_str_new2([[NSString stringWithFormat:mad:"%@/%
s", path, "site_ruby"] UTF8String]));
rb_ary_push(load_path, rb_str_new2([[NSString stringWithFormat:mad:"%@/%
s", path, "1.8"] UTF8String]));
rb_ary_push(load_path, rb_str_new2([[NSString stringWithFormat:mad:"%@/%
s", path, "1.8/powerpc-darwin8.7.0"] UTF8String]));
//rb_p(rb_gv_get("$:"));

-- Daniel
 
N

nobu

Hi,

At Sun, 20 Aug 2006 08:40:19 +0900,
Daniel Harple wrote in [ruby-talk:209438]:
Well, that was dumb of me. This worked:

NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [NSString stringWithFormat:mad:"%@/../Resources/ruby",
[bundle pathForAuxiliaryExecutable:mad:"My App"]];
VALUE load_path = rb_gv_get("$:");
rb_ary_push(load_path, rb_str_new2([[NSString stringWithFormat:mad:"%@/%
s", path, "site_ruby/1.8"] UTF8String]));

Or, you can use ruby_incpush(), which splits path list with
path separator.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top