diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-04-19 19:31:25 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-04-23 09:31:37 -0300 |
commit | 50b6e27d957ca2d994234536452d6d0411eda03a (patch) | |
tree | 16d1805146b8f35e571f33af5ca7516b7d9858ed /src | |
parent | 7c09d1c22cf14ff088b9de4ab214164818fba28a (diff) | |
download | luarocks-50b6e27d957ca2d994234536452d6d0411eda03a.tar.gz luarocks-50b6e27d957ca2d994234536452d6d0411eda03a.tar.bz2 luarocks-50b6e27d957ca2d994234536452d6d0411eda03a.zip |
queries: use metatable for default arch and substring fields
Store default values for the `arch` and `substring` fields of
query objects in the metatable, to avoid storing them in the
actual object for dependency listings, that are persisted in
the manifest.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/queries.lua | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/luarocks/queries.lua b/src/luarocks/queries.lua index 2699aa8c..99728103 100644 --- a/src/luarocks/queries.lua +++ b/src/luarocks/queries.lua | |||
@@ -13,6 +13,18 @@ function query_mt.type() | |||
13 | return "query" | 13 | return "query" |
14 | end | 14 | end |
15 | 15 | ||
16 | -- Fallback default value for the `arch` field, if not explicitly set. | ||
17 | query_mt.arch = { | ||
18 | src = true, | ||
19 | all = true, | ||
20 | rockspec = true, | ||
21 | installed = true, | ||
22 | [cfg.arch] = true, | ||
23 | } | ||
24 | |||
25 | -- Fallback default value for the `substring` field, if not explicitly set. | ||
26 | query_mt.substring = false | ||
27 | |||
16 | --- Convert the arch field of a query table to table format. | 28 | --- Convert the arch field of a query table to table format. |
17 | -- @param input string, table or nil | 29 | -- @param input string, table or nil |
18 | local function arch_to_table(input) | 30 | local function arch_to_table(input) |
@@ -24,14 +36,6 @@ local function arch_to_table(input) | |||
24 | arch[a] = true | 36 | arch[a] = true |
25 | end | 37 | end |
26 | return arch | 38 | return arch |
27 | else | ||
28 | local arch = {} | ||
29 | arch["src"] = true | ||
30 | arch["all"] = true | ||
31 | arch["rockspec"] = true | ||
32 | arch["installed"] = true | ||
33 | arch[cfg.arch] = true | ||
34 | return arch | ||
35 | end | 39 | end |
36 | end | 40 | end |
37 | 41 | ||
@@ -165,8 +169,6 @@ do | |||
165 | name = name, | 169 | name = name, |
166 | namespace = namespace, | 170 | namespace = namespace, |
167 | constraints = constraints, | 171 | constraints = constraints, |
168 | substring = false, | ||
169 | arch = arch_to_table(nil), | ||
170 | } | 172 | } |
171 | return setmetatable(self, query_mt) | 173 | return setmetatable(self, query_mt) |
172 | end | 174 | end |