diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2013-04-30 02:57:50 -0700 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2013-04-30 02:57:50 -0700 |
commit | 6165f2cda31a0ad5330360d2edd7cb480ef52179 (patch) | |
tree | 6e9fb79fa8f765605b997f802ed22f83fad44215 /lualibs-util-env.lua | |
parent | 202f064c65283e482f149868437e2881a73ebe3d (diff) | |
parent | 01fd63f17c80e81218b3d65f1455a62c411dc6ff (diff) | |
download | lualibs-6165f2cda31a0ad5330360d2edd7cb480ef52179.tar.gz |
Merge pull request #3 from phi-gamma/master
sync with context
Diffstat (limited to 'lualibs-util-env.lua')
-rw-r--r-- | lualibs-util-env.lua | 29 |
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) |