diff options
author | starkos <none@none> | 2009-12-17 18:28:39 +0300 |
---|---|---|
committer | starkos <none@none> | 2009-12-17 18:28:39 +0300 |
commit | 5ec7127f5292856d0e9511181a5ab7e4bfc7ba8a (patch) | |
tree | 3cddd78a2a297207f08eadf8c6adf4b401c599d3 /src/base/globals.lua | |
parent | ffd428c8611d1084aae605a3f7492873f3acf574 (diff) |
Feature 2832906: Global variable (_SCRIPT) for current script path
Diffstat (limited to 'src/base/globals.lua')
-rw-r--r-- | src/base/globals.lua | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/base/globals.lua b/src/base/globals.lua index 03bcaee..47966ff 100644 --- a/src/base/globals.lua +++ b/src/base/globals.lua @@ -62,8 +62,9 @@ local builtin_dofile = dofile function dofile(fname) - -- remember the current working directory; I'll restore it shortly + -- remember the current working directory and file; I'll restore it shortly local oldcwd = os.getcwd() + local oldfile = _SCRIPT -- if the file doesn't exist, check the search path if (not os.isfile(fname)) then @@ -75,16 +76,17 @@ -- use the absolute path to the script file, to avoid any file name -- ambiguity if an error should arise - fname = path.getabsolute(fname) + _SCRIPT = path.getabsolute(fname) -- switch the working directory to the new script location - local newcwd = path.getdirectory(fname) + local newcwd = path.getdirectory(_SCRIPT) os.chdir(newcwd) -- run the chunk. How can I catch variable return values? - local a, b, c, d, e, f = builtin_dofile(fname) + local a, b, c, d, e, f = builtin_dofile(_SCRIPT) -- restore the previous working directory when done + _SCRIPT = oldfile os.chdir(oldcwd) return a, b, c, d, e, f end |