From 3d2135842a703edae632f4623f466c0c8132ffb2 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Tue, 30 Jul 2024 21:00:26 +0300 Subject: converted config --- src/luarocks/config-original.lua | 36 ++++++++++++++++++++++++++++++++++++ src/luarocks/config.lua | 6 ++++-- src/luarocks/config.tl | 38 ++++++++++++++++++++++++++++++++++++++ src/luarocks/persist.tl | 7 +++++-- 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 src/luarocks/config-original.lua create mode 100644 src/luarocks/config.tl (limited to 'src') 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 @@ +local config = {} + +local persist = require("luarocks.persist") + +local cfg_skip = { + errorcodes = true, + flags = true, + platforms = true, + root_dir = true, + upload_servers = true, +} + +function config.should_skip(k, v) + return type(v) == "function" or cfg_skip[k] +end + +local function cleanup(tbl) + local copy = {} + for k, v in pairs(tbl) do + if not config.should_skip(k, v) then + copy[k] = v + end + end + return copy +end + +function config.get_config_for_display(cfg) + return cleanup(cfg) +end + +function config.to_string(cfg) + local cleancfg = config.get_config_for_display(cfg) + return persist.save_from_table_to_string(cleancfg) +end + +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 @@ -local config = {} +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 = {} local persist = require("luarocks.persist") @@ -10,6 +10,8 @@ local cfg_skip = { upload_servers = true, } + + function config.should_skip(k, v) return type(v) == "function" or cfg_skip[k] end @@ -17,7 +19,7 @@ end local function cleanup(tbl) local copy = {} for k, v in pairs(tbl) do - if not config.should_skip(k, v) then + if not (type(k) == "string" and config.should_skip(k, v)) then copy[k] = v end 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 @@ +local config = {} + +local persist = require("luarocks.persist") + +local cfg_skip: {string: boolean} = { + errorcodes = true, + flags = true, + platforms = true, + root_dir = true, + upload_servers = true, +} + +local type PersistableTable = persist.PersistableTable + +function config.should_skip(k: string, v: any): boolean + return v is function or cfg_skip[k] +end + +local function cleanup(tbl: PersistableTable): PersistableTable + local copy = {} + for k, v in pairs(tbl) do + if not (k is string and config.should_skip(k, v)) then --? tostring(k) of k is string and... + copy[k] = v + end + end + return copy +end + +function config.get_config_for_display(cfg: PersistableTable): PersistableTable + return cleanup(cfg) +end + +function config.to_string(cfg: PersistableTable): string, string + local cleancfg: PersistableTable = config.get_config_for_display(cfg) + return persist.save_from_table_to_string(cleancfg) +end + +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 @@ local record persist run_file: function(string, {string:any}): boolean, any | string, string load_into_table: function(string, ?{string:any}) : {any: any}, {any: any} | string, string + + type PersistableTable = { string | number : string | number | boolean | PersistableTable } + end local core = require("luarocks.core.persist") @@ -13,7 +16,7 @@ local fs = require("luarocks.fs") local cfg = require("luarocks.core.cfg") local type Config = cfg -local type PersistableTable = { string | number : string | number | boolean | PersistableTable } +local type PersistableTable = persist.PersistableTable persist.run_file = core.run_file persist.load_into_table = core.load_into_table @@ -179,7 +182,7 @@ end -- @param tbl table: the table containing the data to be written -- @param sort_by table: an optional array indicating the order of top-level fields. -- @return persisted data as string; or nil and an error message -function persist.save_from_table_to_string(tbl: PersistableTable, sort_by: util.SortBy): string, string +function persist.save_from_table_to_string(tbl: PersistableTable, sort_by?: util.SortBy): string, string local out: Writer = {buffer = {}} function out:write(data: string) table.insert(self.buffer, data) end local ok, err = write_table_as_assignments(out, tbl, sort_by) -- cgit v1.2.3-55-g6feb