diff options
author | Marius <mariausol@gmail.com> | 2013-04-19 17:40:26 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2013-04-19 17:40:26 +0300 |
commit | b7e0ad6611d168a628cd644b4c6c7a83788e483a (patch) | |
tree | 72c8e0d8fa4899ce271636bfa6da99a3bcf058fa /tex/context/base/util-env.lua | |
parent | 4586560fc032bd763deee980ed5238511be88ba9 (diff) | |
download | context-b7e0ad6611d168a628cd644b4c6c7a83788e483a.tar.gz |
beta 2013.04.19 16:29
Diffstat (limited to 'tex/context/base/util-env.lua')
-rw-r--r-- | tex/context/base/util-env.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tex/context/base/util-env.lua b/tex/context/base/util-env.lua index 283b91c0a..f4f3ef69f 100644 --- a/tex/context/base/util-env.lua +++ b/tex/context/base/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) |