diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-07-30 21:00:26 +0300 |
|---|---|---|
| committer | V1K1NGbg <victor@ilchev.com> | 2024-08-05 20:51:31 +0300 |
| commit | 3d2135842a703edae632f4623f466c0c8132ffb2 (patch) | |
| tree | 7012a0f45e6c0433022cada35b887ecdbe3f028d /src | |
| parent | e8fffcffbb06ad2a77771af5e452645937675066 (diff) | |
| download | luarocks-3d2135842a703edae632f4623f466c0c8132ffb2.tar.gz luarocks-3d2135842a703edae632f4623f466c0c8132ffb2.tar.bz2 luarocks-3d2135842a703edae632f4623f466c0c8132ffb2.zip | |
converted config
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/config-original.lua | 36 | ||||
| -rw-r--r-- | src/luarocks/config.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/config.tl | 38 | ||||
| -rw-r--r-- | src/luarocks/persist.tl | 7 |
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 @@ | |||
| 1 | local config = {} | ||
| 2 | |||
| 3 | local persist = require("luarocks.persist") | ||
| 4 | |||
| 5 | local cfg_skip = { | ||
| 6 | errorcodes = true, | ||
| 7 | flags = true, | ||
| 8 | platforms = true, | ||
| 9 | root_dir = true, | ||
| 10 | upload_servers = true, | ||
| 11 | } | ||
| 12 | |||
| 13 | function config.should_skip(k, v) | ||
| 14 | return type(v) == "function" or cfg_skip[k] | ||
| 15 | end | ||
| 16 | |||
| 17 | local 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 | ||
| 25 | end | ||
| 26 | |||
| 27 | function config.get_config_for_display(cfg) | ||
| 28 | return cleanup(cfg) | ||
| 29 | end | ||
| 30 | |||
| 31 | function config.to_string(cfg) | ||
| 32 | local cleancfg = config.get_config_for_display(cfg) | ||
| 33 | return persist.save_from_table_to_string(cleancfg) | ||
| 34 | end | ||
| 35 | |||
| 36 | return 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 @@ | |||
| 1 | local config = {} | 1 | local _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 | ||
| 3 | local persist = require("luarocks.persist") | 3 | local 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 | |||
| 13 | function config.should_skip(k, v) | 15 | function config.should_skip(k, v) |
| 14 | return type(v) == "function" or cfg_skip[k] | 16 | return type(v) == "function" or cfg_skip[k] |
| 15 | end | 17 | end |
| @@ -17,7 +19,7 @@ end | |||
| 17 | local function cleanup(tbl) | 19 | local 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 @@ | |||
| 1 | local config = {} | ||
| 2 | |||
| 3 | local persist = require("luarocks.persist") | ||
| 4 | |||
| 5 | local cfg_skip: {string: boolean} = { | ||
| 6 | errorcodes = true, | ||
| 7 | flags = true, | ||
| 8 | platforms = true, | ||
| 9 | root_dir = true, | ||
| 10 | upload_servers = true, | ||
| 11 | } | ||
| 12 | |||
| 13 | local type PersistableTable = persist.PersistableTable | ||
| 14 | |||
| 15 | function config.should_skip(k: string, v: any): boolean | ||
| 16 | return v is function or cfg_skip[k] | ||
| 17 | end | ||
| 18 | |||
| 19 | local 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 | ||
| 27 | end | ||
| 28 | |||
| 29 | function config.get_config_for_display(cfg: PersistableTable): PersistableTable | ||
| 30 | return cleanup(cfg) | ||
| 31 | end | ||
| 32 | |||
| 33 | function 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) | ||
| 36 | end | ||
| 37 | |||
| 38 | return 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 @@ | |||
| 4 | local record persist | 4 | local 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 | |||
| 7 | end | 10 | end |
| 8 | 11 | ||
| 9 | local core = require("luarocks.core.persist") | 12 | local core = require("luarocks.core.persist") |
| @@ -13,7 +16,7 @@ local fs = require("luarocks.fs") | |||
| 13 | local cfg = require("luarocks.core.cfg") | 16 | local cfg = require("luarocks.core.cfg") |
| 14 | 17 | ||
| 15 | local type Config = cfg | 18 | local type Config = cfg |
| 16 | local type PersistableTable = { string | number : string | number | boolean | PersistableTable } | 19 | local type PersistableTable = persist.PersistableTable |
| 17 | 20 | ||
| 18 | persist.run_file = core.run_file | 21 | persist.run_file = core.run_file |
| 19 | persist.load_into_table = core.load_into_table | 22 | persist.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 |
| 182 | function persist.save_from_table_to_string(tbl: PersistableTable, sort_by: util.SortBy<number | string>): string, string | 185 | function 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) |
