# Setting \_\_FILE\_\_ impossible with rb\_eval\_string() - hack ide

**URL:** <https://www.ruby-forum.com/t/setting-file-impossible-with-rb-eval-string-hack-ide/80922>\
**Category:** Ruby\
**Created:** [January 2, 2007, 3:40am UTC](https://www.ruby-forum.com/t/setting-file-impossible-with-rb-eval-string-hack-ide/80922 "2007-01-02T03:40:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![John-Mason\_PSShack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/94ad74/32.png) [@John-Mason\_PSShack](https://www.ruby-forum.com/u/John-Mason_PSShack)\
**Post date:** [January 2, 2007, 3:40am UTC](https://www.ruby-forum.com/t/setting-file-impossible-with-rb-eval-string-hack-ide/80922/1 "2007-01-02T03:40:46Z")

</div>

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  
removed\_email\_address@domain.invalid  
[http://pearsonedmeasurement.com](http://pearsonedmeasurement.com)
