annotate share/lua/5.2/luarocks/loader.lua @ 12500:e48c08805365 draft default tip

<b_jonas> ` learn \'The password of the month is Cthulhuquagdonic Mothraquagdonic Narwhalicorn.\' # https://logs.esolangs.org/libera-esolangs/2024-04.html#lKE Infinite craft
author HackEso <hackeso@esolangs.org>
date Wed, 01 May 2024 06:39:10 +0000
parents d137f631bad5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1132
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
1
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
2 --- A module which installs a Lua package loader that is LuaRocks-aware.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
3 -- This loader uses dependency information from the LuaRocks tree to load
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
4 -- correct versions of modules. It does this by constructing a "context"
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
5 -- table in the environment, which records which versions of packages were
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
6 -- used to load previous modules, so that the loader chooses versions
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
7 -- that are declared to be compatible with the ones loaded earlier.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
8 local global_env = _G
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
9 local package, require, ipairs, pairs, table, type, next, unpack =
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
10 package, require, ipairs, pairs, table, type, next, unpack
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
11
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
12 module("luarocks.loader")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
13
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
14 local path = require("luarocks.path")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
15 local manif_core = require("luarocks.manif_core")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
16 local deps = require("luarocks.deps")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
17 local cfg = require("luarocks.cfg")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
18
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
19 context = {}
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
20
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
21 -- Contains a table when rocks trees are loaded,
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
22 -- or 'false' to indicate rocks trees failed to load.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
23 -- 'nil' indicates rocks trees were not attempted to be loaded yet.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
24 rocks_trees = nil
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
25
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
26 local function load_rocks_trees()
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
27 local any_ok = false
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
28 local trees = {}
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
29 for _, tree in ipairs(cfg.rocks_trees) do
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
30 local manifest, err = manif_core.load_local_manifest(path.rocks_dir(tree))
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
31 if manifest then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
32 any_ok = true
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
33 table.insert(trees, {tree=tree, manifest=manifest})
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
34 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
35 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
36 if not any_ok then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
37 rocks_trees = false
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
38 return false
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
39 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
40 rocks_trees = trees
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
41 return true
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
42 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
43
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
44 --- Process the dependencies of a package to determine its dependency
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
45 -- chain for loading modules.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
46 -- @param name string: The name of an installed rock.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
47 -- @param version string: The version of the rock, in string format
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
48 function add_context(name, version)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
49 -- assert(type(name) == "string")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
50 -- assert(type(version) == "string")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
51
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
52 if context[name] then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
53 return
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
54 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
55 context[name] = version
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
56
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
57 if not rocks_trees and not load_rocks_trees() then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
58 return nil
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
59 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
60
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
61 local providers = {}
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
62 for _, tree in ipairs(rocks_trees) do
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
63 local manifest = tree.manifest
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
64
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
65 local pkgdeps
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
66 if manifest.dependencies and manifest.dependencies[name] then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
67 pkgdeps = manifest.dependencies[name][version]
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
68 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
69 if not pkgdeps then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
70 return nil
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
71 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
72 for _, dep in ipairs(pkgdeps) do
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
73 local pkg, constraints = dep.name, dep.constraints
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
74
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
75 for _, tree in ipairs(rocks_trees) do
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
76 local entries = tree.manifest.repository[pkg]
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
77 if entries then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
78 for version, pkgs in pairs(entries) do
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
79 if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
80 add_context(pkg, version)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
81 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
82 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
83 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
84 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
85 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
86 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
87 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
88
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
89 --- Internal sorting function.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
90 -- @param a table: A provider table.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
91 -- @param b table: Another provider table.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
92 -- @return boolean: True if the version of a is greater than that of b.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
93 local function sort_versions(a,b)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
94 return a.version > b.version
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
95 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
96
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
97 --- Request module to be loaded through other loaders,
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
98 -- once the proper name of the module has been determined.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
99 -- For example, in case the module "socket.core" has been requested
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
100 -- to the LuaRocks loader and it determined based on context that
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
101 -- the version 2.0.2 needs to be loaded and it is not the current
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
102 -- version, the module requested for the other loaders will be
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
103 -- "socket.core_2_0_2".
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
104 -- @param module The module name requested by the user, such as "socket.core"
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
105 -- @param name The rock name, such as "luasocket"
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
106 -- @param version The rock version, such as "2.0.2-1"
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
107 -- @param module_name The actual module name, such as "socket.core" or "socket.core_2_0_2".
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
108 -- @return table or (nil, string): The module table as returned by some other loader,
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
109 -- or nil followed by an error message if no other loader managed to load the module.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
110 local function call_other_loaders(module, name, version, module_name)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
111 for i, loader in pairs(package.loaders) do
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
112 if loader ~= luarocks_loader then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
113 local results = { loader(module_name) }
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
114 if type(results[1]) == "function" then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
115 return unpack(results)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
116 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
117 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
118 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
119 return "Failed loading module "..module.." in LuaRocks rock "..name.." "..version
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
120 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
121
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
122 --- Search for a module in the rocks trees
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
123 -- @param module string: module name (eg. "socket.core")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
124 -- @param filter_module_name function(string, string, string, string, number):
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
125 -- a function that takes the module name (eg "socket.core"), the rock name
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
126 -- (eg "luasocket"), the version (eg "2.0.2-1"), the path of the rocks tree
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
127 -- (eg "/usr/local"), and the numeric index of the matching entry, so the
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
128 -- filter function can know if the matching module was the first entry or not.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
129 -- @return string, string, string: name of the rock containing the module
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
130 -- (eg. "luasocket"), version of the rock (eg. "2.0.2-1"),
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
131 -- name of the module (eg. "socket.core", or "socket.core_2_0_2" if file is
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
132 -- stored versioned).
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
133 local function select_module(module, filter_module_name)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
134 --assert(type(module) == "string")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
135 --assert(type(filter_module_name) == "function")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
136
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
137 if not rocks_trees and not load_rocks_trees() then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
138 return nil
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
139 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
140
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
141 local providers = {}
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
142 for _, tree in ipairs(rocks_trees) do
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
143 local entries = tree.manifest.modules[module]
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
144 if entries then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
145 for i, entry in ipairs(entries) do
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
146 local name, version = entry:match("^([^/]*)/(.*)$")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
147 local module_name = tree.manifest.repository[name][version][1].modules[module]
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
148 if type(module_name) ~= "string" then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
149 error("Invalid format in manifest file (invalid data for "..tostring(name).." "..tostring(version)..")")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
150 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
151 module_name = filter_module_name(module_name, name, version, tree.tree, i)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
152 if context[name] == version then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
153 return name, version, module_name
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
154 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
155 version = deps.parse_version(version)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
156 table.insert(providers, {name = name, version = version, module_name = module_name})
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
157 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
158 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
159 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
160
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
161 if next(providers) then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
162 table.sort(providers, sort_versions)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
163 local first = providers[1]
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
164 return first.name, first.version.string, first.module_name
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
165 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
166 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
167
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
168 --- Search for a module
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
169 -- @param module string: module name (eg. "socket.core")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
170 -- @return string, string, string: name of the rock containing the module
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
171 -- (eg. "luasocket"), version of the rock (eg. "2.0.2-1"),
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
172 -- name of the module (eg. "socket.core", or "socket.core_2_0_2" if file is
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
173 -- stored versioned).
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
174 local function pick_module(module)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
175 return
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
176 select_module(module, function(module_name, name, version, tree, i)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
177 if i > 1 then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
178 module_name = path.versioned_name(module_name, "", name, version)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
179 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
180 module_name = path.path_to_module(module_name)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
181 return module_name
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
182 end)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
183 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
184
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
185 --- Return the pathname of the file that would be loaded for a module.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
186 -- @param module string: module name (eg. "socket.core")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
187 -- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
188 function which(module)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
189 local name, version, module_name = select_module(module, path.which_i)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
190 return module_name
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
191 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
192
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
193 --- Package loader for LuaRocks support.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
194 -- A module is searched in installed rocks that match the
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
195 -- current LuaRocks context. If module is not part of the
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
196 -- context, or if a context has not yet been set, the module
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
197 -- in the package with the highest version is used.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
198 -- @param module string: The module name, like in plain require().
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
199 -- @return table: The module table (typically), like in plain
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
200 -- require(). See <a href="http://www.lua.org/manual/5.1/manual.html#pdf-require">require()</a>
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
201 -- in the Lua reference manual for details.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
202 function luarocks_loader(module)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
203 local name, version, module_name = pick_module(module)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
204 if not name then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
205 return "No LuaRocks module found for "..module
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
206 else
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
207 add_context(name, version)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
208 return call_other_loaders(module, name, version, module_name)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
209 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
210 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
211
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
212 table.insert(global_env.package.loaders, 1, luarocks_loader)