Feature - Rejected change __FILE__ or make new similar

Currently I have two scripts that both import a shared script. One handy thing this shared script does is resource management, and it currently tries to use __FILE__ to know which script is using it... but I just realized after some severe bugs were happening that __FILE__ returns the name of the file it is in, not the name of the current running script. Would it damage anything to change __FILE__ to return the name of the executing script, or can we get a new variable that returns the name of the running script instead?
 

fronobulax

Developer
Staff member
Just where is __FILE__ documented? ;-) It is set by the Parser and there it is the name of the file being parsed which is just what you are seeing. Under the circumstances what might be more feasible is something that returns the name of the currently running script. If you are using the MRU feature in the scripts menu and if the value there is what you want, maybe exposing it would be feasible as an alternative?
 
Just where is __FILE__ documented? ;-) It is set by the Parser and there it is the name of the file being parsed which is just what you are seeing. Under the circumstances what might be more feasible is something that returns the name of the currently running script. If you are using the MRU feature in the scripts menu and if the value there is what you want, maybe exposing it would be feasible as an alternative?

I'm not really sure what you mean about using the MRU... though the value would be there, I wouldn't be able to know which slot is which...

ANYWAY, I found a pretty decent solution to my problem.
Shared Script
Code:
string NAME=__FILE__;
void setName(string newName){
 NAME=newName;
}
...
And all the other scripts:
Code:
import <shared.ash>
setName(__FILE__);
Which is pretty minimal work and I'm saddened by myself for not thinking of it before submitting my feature request.
 

fronobulax

Developer
Staff member
@border - The MRU stuff just grabs the name of a file when a script is executed in one of several ways. If that name was the right one for your purposes then it could be exposed. But that is a moot point now.

@Bale - OK. When I searched for _FILE on the wiki there were no hits. __FILE__ did turn up some so my error was in thinking the wiki search would match a substring. I concur with marking this Rejected, not that matters.
 
Top