From 606c29d80dd939cccc21c7278cc20d3300df2576 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 26 Sep 2013 02:12:25 -0300 Subject: Remove trailing space from dir_name; do not rely on setfenv to check for Lua 5.1, this breaks users of 'strict' globals checker --- src/luarocks/dir.lua | 7 +++---- src/luarocks/persist.lua | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua index b496c962..3c7465bb 100644 --- a/src/luarocks/dir.lua +++ b/src/luarocks/dir.lua @@ -17,13 +17,12 @@ end --- Strip the name off a path+filename. -- @param pathname string: A path+name, such as "/a/b/c". --- @return string: The filename without its path, such as "/a/b/". --- For entries such as "/a/b/", "/a/" is returned. If there are +-- @return string: The filename without its path, such as "/a/b". +-- For entries such as "/a/b/", "/a" is returned. If there are -- no directory separators in input, "" is returned. function dir_name(pathname) assert(type(pathname) == "string") - - return (pathname:gsub("/*$", ""):match("(.*/)[^/]*")) or "" + return (pathname:gsub("/*$", ""):match("(.*)[/]+[^/]*")) or "" end --- Describe a path in a cross-platform way. diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua index 208aee02..376a242a 100644 --- a/src/luarocks/persist.lua +++ b/src/luarocks/persist.lua @@ -20,7 +20,7 @@ function load_into_table(filename, tbl) local result, chunk, ran, err local result = tbl or {} - if setfenv then -- Lua 5.1 + if _VERSION == "Lua 5.1" then -- Lua 5.1 chunk, err = loadfile(filename) if chunk then setfenv(chunk, result) -- cgit v1.2.3-55-g6feb