Re: Include File Relative Paths
- Posted by c.k.lester <euphoric at cklester.com> Mar 08, 2007
- 545 views
Pete Lomax wrote: > c.k.lester wrote: > > I don't think a variable in the global namespace is proper in this case > > (or ever, really) when all I'm trying to do is open a file relative to > > the calling file. > You seem to miss the point that you cannot and must not change open(). > You will break thousands of existing programs (including Edita!). How will it break it if all it does it look one more place for a file it is trying to open, which would have crashed in the past? > However I suppose you could do this: > 1) extend the enhancements to path_open so that the new currdir variable is > always left with whatever path actually succeeded. > 2) add a new builtin open_relative(name,mode) which is just like open except > that > it emits tmp=currdir&name open(tmp,mode). I suspect #2 would suffice. It would be the enhanced open(), which I would then use all the time. Why not? :) > > When somebody takes my c:\htdocs\plugins\superPlugin code directory and puts > > it into their program's directory (which might be z:\net\htdocs\release\, > > they can simply include the include file and it will all work... no include > > path modifications required. That's how it should be. > > Wait a minute here. So you are saying that they can dump it in \release, or > \release\superPlugin, or \release\junk and it has to work in all cases?? Yes, which isn't that amazing. It happens in PHP all the time. I'm sure other languages handle it just fine. > Otherwise why not just use a "superPlugin" constant?? I've resorted to a plugins constant for now. > Or are you saying you > have a component and you don't want to tell it what it is part of? Why not? The plugins basically add things to the entire setup with code like add_script("text/javascript", "plugins/jquery/res/jquery-latest.js" ) which, with relative open(), would be add_script("text/javascript", "res/jquery-latest.js" ) meaning that 'plugins' and 'jquery' can be user definable without any user modification to the plugin code. But now I'm doing this (lame): add_script("text/javascript", PLUGINS_DIR & "jquery/res/jquery-latest.js" ) which is still not optimal because the file resides in jquery, yet it has to specify itself. LAME! I just like flexibility (and portability) (and modularity), to an extreme. :)