summaryrefslogtreecommitdiff
path: root/lualibs-util-env.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-04-30 11:55:11 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2013-04-30 11:55:11 +0200
commit01fd63f17c80e81218b3d65f1455a62c411dc6ff (patch)
tree6e9fb79fa8f765605b997f802ed22f83fad44215 /lualibs-util-env.lua
parent1e04ecc2c4918448e8ff30a2e6363025267cac79 (diff)
downloadlualibs-01fd63f17c80e81218b3d65f1455a62c411dc6ff.tar.gz
sync with Context from 2013-04-30
Diffstat (limited to 'lualibs-util-env.lua')
-rw-r--r--lualibs-util-env.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/lualibs-util-env.lua b/lualibs-util-env.lua
index 283b91c..f4f3ef6 100644
--- a/lualibs-util-env.lua
+++ b/lualibs-util-env.lua
@@ -206,6 +206,35 @@ function environment.reconstructcommandline(arg,noquote)
end
end
+-- handy in e.g. package.addluapath(environment.relativepath("scripts"))
+
+function environment.relativepath(path,root)
+ if not path then
+ path = ""
+ end
+ if not file.is_rootbased_path(path) then
+ if not root then
+ root = file.pathpart(environment.ownscript or environment.ownname or ".")
+ end
+ if root == "" then
+ root = "."
+ end
+ path = root .. "/" .. path
+ end
+ return file.collapsepath(path,true)
+end
+
+-- -- when script lives on e:/tmp we get this:
+--
+-- print(environment.relativepath("x/y/z","c:/w")) -- c:/w/x/y/z
+-- print(environment.relativepath("x")) -- e:/tmp/x
+-- print(environment.relativepath("../x")) -- e:/x
+-- print(environment.relativepath("./x")) -- e:/tmp/x
+-- print(environment.relativepath("/x")) -- /x
+-- print(environment.relativepath("c:/x")) -- c:/x
+-- print(environment.relativepath("//x")) -- //x
+-- print(environment.relativepath()) -- e:/tmp
+
-- -- to be tested:
--
-- function environment.reconstructcommandline(arg,noquote)