lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I don’t know if this has been discussed before but would it possible to add the starting (main) script's path in the default search of directories when doing ‘require’?  And, preferably as the first place to look.
 
Usually, apps and all their app-specific related modules (other than the general-purpose libraries) are all located in a single folder.
 
So, while “require ‘module’” searches for ./module (where “.” is rather arbitrary because one may be in any subdirectory when starting to run the program) it does not search the app’s path.
 
To make it clearer, assume this (for Windows):
 
\progs\lua\app.lua
\progs\lua\app_lib.lua
 
app.lua starts with “require ‘app’”
 
If I run app.lua from inside \progs\lua, no problem – app_lib.lua is found and loaded.  But, if I go to a different directory (say, \temp), and run it from there using the full path (\progs\lua\app.lua), it will not find app_lib.lua anymore.
 
I think the first place to look for required modules would be the (main) script’s directory.  That also allows to override general libraries with customized versions using the same name but placing them in the app’s folder.
 
Thanks.