aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-07-30 21:00:26 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-05 20:51:31 +0300
commit3d2135842a703edae632f4623f466c0c8132ffb2 (patch)
tree7012a0f45e6c0433022cada35b887ecdbe3f028d
parente8fffcffbb06ad2a77771af5e452645937675066 (diff)
downloadluarocks-3d2135842a703edae632f4623f466c0c8132ffb2.tar.gz
luarocks-3d2135842a703edae632f4623f466c0c8132ffb2.tar.bz2
luarocks-3d2135842a703edae632f4623f466c0c8132ffb2.zip
converted config
-rw-r--r--src/luarocks/config-original.lua36
-rw-r--r--src/luarocks/config.lua6
-rw-r--r--src/luarocks/config.tl38
-rw-r--r--src/luarocks/persist.tl7
4 files changed, 83 insertions, 4 deletions
diff --git a/src/luarocks/config-original.lua b/src/luarocks/config-original.lua
new file mode 100644
index 00000000..019b3885
--- /dev/null
+++ b/src/luarocks/config-original.lua
@@ -0,0 +1,36 @@
1local config = {}
2
3local persist = require("luarocks.persist")
4
5local cfg_skip = {
6 errorcodes = true,
7 flags = true,
8 platforms = true,
9 root_dir = true,
10 upload_servers = true,
11}
12
13function config.should_skip(k, v)
14 return type(v) == "function" or cfg_skip[k]
15end
16
17local function cleanup(tbl)
18 local copy = {}
19 for k, v in pairs(tbl) do
20 if not config.should_skip(k, v) then
21 copy[k] = v
22 end
23 end
24 return copy
25end
26
27function config.get_config_for_display(cfg)
28 return cleanup(cfg)
29end
30
31function config.to_string(cfg)
32 local cleancfg = config.get_config_for_display(cfg)
33 return persist.save_from_table_to_string(cleancfg)
34end
35
36return config
diff --git a/src/luarocks/config.lua b/src/luarocks/config.lua
index 019b3885..18ec90da 100644
--- a/src/luarocks/config.lua
+++ b/src/luarocks/config.lua
@@ -1,4 +1,4 @@
1local config = {} 1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local pairs = _tl_compat and _tl_compat.pairs or pairs; local config = {}
2 2
3local persist = require("luarocks.persist") 3local persist = require("luarocks.persist")
4 4
@@ -10,6 +10,8 @@ local cfg_skip = {
10 upload_servers = true, 10 upload_servers = true,
11} 11}
12 12
13
14
13function config.should_skip(k, v) 15function config.should_skip(k, v)
14 return type(v) == "function" or cfg_skip[k] 16 return type(v) == "function" or cfg_skip[k]
15end 17end
@@ -17,7 +19,7 @@ end
17local function cleanup(tbl) 19local function cleanup(tbl)
18 local copy = {} 20 local copy = {}
19 for k, v in pairs(tbl) do 21 for k, v in pairs(tbl) do
20 if not config.should_skip(k, v) then 22 if not (type(k) == "string" and config.should_skip(k, v)) then
21 copy[k] = v 23 copy[k] = v
22 end 24 end
23 end 25 end
diff --git a/src/luarocks/config.tl b/src/luarocks/config.tl
new file mode 100644
index 00000000..93347453
--- /dev/null
+++ b/src/luarocks/config.tl
@@ -0,0 +1,38 @@
1local config = {}
2
3local persist = require("luarocks.persist")
4
5local cfg_skip: {string: boolean} = {
6 errorcodes = true,
7 flags = true,
8 platforms = true,
9 root_dir = true,
10 upload_servers = true,
11}
12
13local type PersistableTable = persist.PersistableTable
14
15function config.should_skip(k: string, v: any): boolean
16 return v is function or cfg_skip[k]
17end
18
19local function cleanup(tbl: PersistableTable): PersistableTable
20 local copy = {}
21 for k, v in pairs(tbl) do
22 if not (k is string and config.should_skip(k, v)) then --? tostring(k) of k is string and...
23 copy[k] = v
24 end
25 end
26 return copy
27end
28
29function config.get_config_for_display(cfg: PersistableTable): PersistableTable
30 return cleanup(cfg)
31end
32
33function config.to_string(cfg: PersistableTable): string, string
34 local cleancfg: PersistableTable = config.get_config_for_display(cfg)
35 return persist.save_from_table_to_string(cleancfg)
36end
37
38return config
diff --git a/src/luarocks/persist.tl b/src/luarocks/persist.tl
index de8f3faf..64b76639 100644
--- a/src/luarocks/persist.tl
+++ b/src/luarocks/persist.tl
@@ -4,6 +4,9 @@
4local record persist 4local record persist
5 run_file: function(string, {string:any}): boolean, any | string, string 5 run_file: function(string, {string:any}): boolean, any | string, string
6 load_into_table: function(string, ?{string:any}) : {any: any}, {any: any} | string, string 6 load_into_table: function(string, ?{string:any}) : {any: any}, {any: any} | string, string
7
8 type PersistableTable = { string | number : string | number | boolean | PersistableTable }
9
7end 10end
8 11
9local core = require("luarocks.core.persist") 12local core = require("luarocks.core.persist")
@@ -13,7 +16,7 @@ local fs = require("luarocks.fs")
13local cfg = require("luarocks.core.cfg") 16local cfg = require("luarocks.core.cfg")
14 17
15local type Config = cfg 18local type Config = cfg
16local type PersistableTable = { string | number : string | number | boolean | PersistableTable } 19local type PersistableTable = persist.PersistableTable
17 20
18persist.run_file = core.run_file 21persist.run_file = core.run_file
19persist.load_into_table = core.load_into_table 22persist.load_into_table = core.load_into_table
@@ -179,7 +182,7 @@ end
179-- @param tbl table: the table containing the data to be written 182-- @param tbl table: the table containing the data to be written
180-- @param sort_by table: an optional array indicating the order of top-level fields. 183-- @param sort_by table: an optional array indicating the order of top-level fields.
181-- @return persisted data as string; or nil and an error message 184-- @return persisted data as string; or nil and an error message
182function persist.save_from_table_to_string(tbl: PersistableTable, sort_by: util.SortBy<number | string>): string, string 185function persist.save_from_table_to_string(tbl: PersistableTable, sort_by?: util.SortBy<number | string>): string, string
183 local out: Writer = {buffer = {}} 186 local out: Writer = {buffer = {}}
184 function out:write(data: string) table.insert(self.buffer, data) end 187 function out:write(data: string) table.insert(self.buffer, data) end
185 local ok, err = write_table_as_assignments(out, tbl, sort_by) 188 local ok, err = write_table_as_assignments(out, tbl, sort_by)