setting __FILE__ impossible with rb_eval_string() - hack ideas?

  • Thread starter John-Mason P. Shackelford
  • Start date
J

John-Mason P. Shackelford

In the following C code:

int main(const int argc, const char ** argv){
ruby_init();
ruby_init_loadpath();
ruby_script(argv[0]);
ruby_sourcefile = rb_source_filename(argv[0]);
rb_eval_string("puts __FILE__"); /* --> returns (eval) wanted argv[0] */
rb_eval_string("puts $0");
return 0;
}

my attempts to to set a value for __FILE__ fail because rb_eval_string
resets it to "(eval)" every time as shown below:

----- eval.c -----
01600 VALUE
01601 rb_eval_string(str)
01602 const char *str;
01603 {
01604 VALUE v;
01605 NODE *oldsrc = ruby_current_node;
01606
01607 ruby_current_node = 0;
01608 ruby_sourcefile = rb_source_filename("(eval)");
01609 v = eval(ruby_top_self, rb_str_new2(str), Qnil, 0, 0);
01610 ruby_current_node = oldsrc;
01611
01612 return v;
01613 }

Can anyone suggest a clever hack ( C novice here ) so that I can reset
__FILE__ to argv[0]? I thought that perhaps I could just call eval
directly but I can't seem to grab ruby_top_self from within the
context of my application, but I am a C ignoramus so I may be missing
something obvious.

I'd be grateful for any pointers (he, he).
--
John-Mason Shackelford

Software Developer
Pearson Educational Measurement

2510 North Dodge St.
Iowa City, IA 52245
ph. 319-354-9200x6214
(e-mail address removed)
http://pearsonedmeasurement.com
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top