aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormpeterv <mpeterval@gmail.com>2016-02-02 17:34:50 +0300
committermpeterv <mpeterval@gmail.com>2016-02-02 17:42:05 +0300
commitd9ffeaf66f77dc9321a574f6aec2df1785acb8e5 (patch)
tree9024aa6296dacc65b278d0e5beead87513a669de /src
parent79f5022066c4d801d973769fe092280e24461cc2 (diff)
downloadluarocks-d9ffeaf66f77dc9321a574f6aec2df1785acb8e5.tar.gz
luarocks-d9ffeaf66f77dc9321a574f6aec2df1785acb8e5.tar.bz2
luarocks-d9ffeaf66f77dc9321a574f6aec2df1785acb8e5.zip
Fix docs for path.which_i and some of its users
It actually accepts file name of the module as in manifest.repository[package][version].modules[module], not the module name.
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/loader.lua29
-rw-r--r--src/luarocks/path.lua19
2 files changed, 24 insertions, 24 deletions
diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua
index ba15613e..26280e94 100644
--- a/src/luarocks/loader.lua
+++ b/src/luarocks/loader.lua
@@ -126,17 +126,17 @@ end
126 126
127--- Search for a module in the rocks trees 127--- Search for a module in the rocks trees
128-- @param module string: module name (eg. "socket.core") 128-- @param module string: module name (eg. "socket.core")
129-- @param filter_module_name function(string, string, string, string, number): 129-- @param filter_file_name function(string, string, string, string, number):
130-- a function that takes the module name (eg "socket.core"), the rock name 130-- a function that takes the module file name (eg "socket/core.so"), the rock name
131-- (eg "luasocket"), the version (eg "2.0.2-1"), the path of the rocks tree 131-- (eg "luasocket"), the version (eg "2.0.2-1"), the path of the rocks tree
132-- (eg "/usr/local"), and the numeric index of the matching entry, so the 132-- (eg "/usr/local"), and the numeric index of the matching entry, so the
133-- filter function can know if the matching module was the first entry or not. 133-- filter function can know if the matching module was the first entry or not.
134-- @return string, string, string, (string or table): 134-- @return string, string, string, (string or table):
135-- * name of the rock containing the module (eg. "luasocket") 135-- * name of the rock containing the module (eg. "luasocket")
136-- * version of the rock (eg. "2.0.2-1") 136-- * version of the rock (eg. "2.0.2-1")
137-- * name of the module (eg. "socket.core", or "socket.core_2_0_2" if file is stored versioned). 137-- * return value of filter_file_name
138-- * tree of the module (string or table in `rocks_trees` format) 138-- * tree of the module (string or table in `rocks_trees` format)
139local function select_module(module, filter_module_name) 139local function select_module(module, filter_file_name)
140 --assert(type(module) == "string") 140 --assert(type(module) == "string")
141 --assert(type(filter_module_name) == "function") 141 --assert(type(filter_module_name) == "function")
142 142
@@ -150,16 +150,16 @@ local function select_module(module, filter_module_name)
150 if entries then 150 if entries then
151 for i, entry in ipairs(entries) do 151 for i, entry in ipairs(entries) do
152 local name, version = entry:match("^([^/]*)/(.*)$") 152 local name, version = entry:match("^([^/]*)/(.*)$")
153 local module_name = tree.manifest.repository[name][version][1].modules[module] 153 local file_name = tree.manifest.repository[name][version][1].modules[module]
154 if type(module_name) ~= "string" then 154 if type(file_name) ~= "string" then
155 error("Invalid data in manifest file for module "..tostring(module).." (invalid data for "..tostring(name).." "..tostring(version)..")") 155 error("Invalid data in manifest file for module "..tostring(module).." (invalid data for "..tostring(name).." "..tostring(version)..")")
156 end 156 end
157 module_name = filter_module_name(module_name, name, version, tree.tree, i) 157 file_name = filter_file_name(file_name, name, version, tree.tree, i)
158 if loader.context[name] == version then 158 if loader.context[name] == version then
159 return name, version, module_name 159 return name, version, file_name
160 end 160 end
161 version = deps.parse_version(version) 161 version = deps.parse_version(version)
162 table.insert(providers, {name = name, version = version, module_name = module_name, tree = tree}) 162 table.insert(providers, {name = name, version = version, module_name = file_name, tree = tree})
163 end 163 end
164 end 164 end
165 end 165 end
@@ -180,12 +180,11 @@ end
180-- * tree of the module (string or table in `rocks_trees` format) 180-- * tree of the module (string or table in `rocks_trees` format)
181local function pick_module(module) 181local function pick_module(module)
182 return 182 return
183 select_module(module, function(module_name, name, version, tree, i) 183 select_module(module, function(file_name, name, version, tree, i)
184 if i > 1 then 184 if i > 1 then
185 module_name = path.versioned_name(module_name, "", name, version) 185 file_name = path.versioned_name(file_name, "", name, version)
186 end 186 end
187 module_name = path.path_to_module(module_name) 187 return path.path_to_module(file_name)
188 return module_name
189 end) 188 end)
190end 189end
191 190
@@ -193,8 +192,8 @@ end
193-- @param module string: module name (eg. "socket.core") 192-- @param module string: module name (eg. "socket.core")
194-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") 193-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
195function loader.which(module) 194function loader.which(module)
196 local name, version, module_name = select_module(module, path.which_i) 195 local _, _, file_name = select_module(module, path.which_i)
197 return module_name 196 return file_name
198end 197end
199 198
200--- Package loader for LuaRocks support. 199--- Package loader for LuaRocks support.
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index fb5eec7e..bc7ab63b 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -342,44 +342,45 @@ end
342local is_src_extension = { [".lua"] = true, [".tl"] = true, [".tld"] = true, [".moon"] = true } 342local is_src_extension = { [".lua"] = true, [".tl"] = true, [".tld"] = true, [".moon"] = true }
343 343
344--- Return the pathname of the file that would be loaded for a module, indexed. 344--- Return the pathname of the file that would be loaded for a module, indexed.
345-- @param module_name string: module name (eg. "socket.core") 345-- @param file_name string: module file name as in manifest (eg. "socket/core.so")
346-- @param name string: name of the package (eg. "luasocket") 346-- @param name string: name of the package (eg. "luasocket")
347-- @param version string: version number (eg. "2.0.2-1") 347-- @param version string: version number (eg. "2.0.2-1")
348-- @param tree string: repository path (eg. "/usr/local") 348-- @param tree string: repository path (eg. "/usr/local")
349-- @param i number: the index, 1 if version is the current default, > 1 otherwise. 349-- @param i number: the index, 1 if version is the current default, > 1 otherwise.
350-- This is done this way for use by select_module in luarocks.loader. 350-- This is done this way for use by select_module in luarocks.loader.
351-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") 351-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
352function path.which_i(module_name, name, version, tree, i) 352function path.which_i(file_name, name, version, tree, i)
353 local deploy_dir 353 local deploy_dir
354 local extension = module_name:match("%.[a-z]+$") 354 local extension = file_name:match("%.[a-z]+$")
355 if is_src_extension[extension] then 355 if is_src_extension[extension] then
356 deploy_dir = path.deploy_lua_dir(tree) 356 deploy_dir = path.deploy_lua_dir(tree)
357 module_name = dir.path(deploy_dir, module_name) 357 file_name = dir.path(deploy_dir, file_name)
358 else 358 else
359 deploy_dir = path.deploy_lib_dir(tree) 359 deploy_dir = path.deploy_lib_dir(tree)
360 module_name = dir.path(deploy_dir, module_name) 360 file_name = dir.path(deploy_dir, file_name)
361 end 361 end
362 if i > 1 then 362 if i > 1 then
363 module_name = path.versioned_name(module_name, deploy_dir, name, version) 363 file_name = path.versioned_name(file_name, deploy_dir, name, version)
364 end 364 end
365 return module_name 365 return file_name
366end 366end
367 367
368--- Return the pathname of the file that would be loaded for a module, 368--- Return the pathname of the file that would be loaded for a module,
369-- returning the versioned pathname if given version is not the default version 369-- returning the versioned pathname if given version is not the default version
370-- in the given manifest. 370-- in the given manifest.
371-- @param module_name string: module name (eg. "socket.core") 371-- @param module_name string: module name (eg. "socket.core")
372-- @param file_name string: module file name as in manifest (eg. "socket/core.so")
372-- @param name string: name of the package (eg. "luasocket") 373-- @param name string: name of the package (eg. "luasocket")
373-- @param version string: version number (eg. "2.0.2-1") 374-- @param version string: version number (eg. "2.0.2-1")
374-- @param tree string: repository path (eg. "/usr/local") 375-- @param tree string: repository path (eg. "/usr/local")
375-- @param manifest table: the manifest table for the tree. 376-- @param manifest table: the manifest table for the tree.
376-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") 377-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
377function path.which(module_name, filename, name, version, tree, manifest) 378function path.which(module_name, file_name, name, version, tree, manifest)
378 local versions = manifest.modules[module_name] 379 local versions = manifest.modules[module_name]
379 assert(versions) 380 assert(versions)
380 for i, name_version in ipairs(versions) do 381 for i, name_version in ipairs(versions) do
381 if name_version == name.."/"..version then 382 if name_version == name.."/"..version then
382 return path.which_i(filename, name, version, tree, i):gsub("//", "/") 383 return path.which_i(file_name, name, version, tree, i):gsub("//", "/")
383 end 384 end
384 end 385 end
385 assert(false) 386 assert(false)