From 3c94f9c1c6b8dbe25d53f4e9701c737ee56bac00 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 31 Aug 2021 10:57:24 +0200 Subject: [PATCH] feat: some parsing improvement --- sonic-radiance.love/birb/utils/bools.lua | 15 ++++++++++++++ sonic-radiance.love/birb/utils/string.lua | 2 +- sonic-radiance.love/birb/utils/table.lua | 24 ++++++++++++----------- 3 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 sonic-radiance.love/birb/utils/bools.lua diff --git a/sonic-radiance.love/birb/utils/bools.lua b/sonic-radiance.love/birb/utils/bools.lua new file mode 100644 index 0000000..2f43829 --- /dev/null +++ b/sonic-radiance.love/birb/utils/bools.lua @@ -0,0 +1,15 @@ +local Bools = {} + +function Bools.either(bool, val1, val2) + if (bool) then + return val1 + else + return val2 + end +end + +function Bools.toString(bool) + return Bools.either(bool, "true", "false") +end + +return Bools diff --git a/sonic-radiance.love/birb/utils/string.lua b/sonic-radiance.love/birb/utils/string.lua index 2ad8f7b..68eca05 100644 --- a/sonic-radiance.love/birb/utils/string.lua +++ b/sonic-radiance.love/birb/utils/string.lua @@ -21,6 +21,6 @@ function String.split(pString, pPattern) table.insert(Table, cap) end return Table - end +end return String \ No newline at end of file diff --git a/sonic-radiance.love/birb/utils/table.lua b/sonic-radiance.love/birb/utils/table.lua index 0c3b0d2..ce08309 100644 --- a/sonic-radiance.love/birb/utils/table.lua +++ b/sonic-radiance.love/birb/utils/table.lua @@ -22,6 +22,7 @@ ]] local Table = {} +local Bools = require "birb.utils.bools" --- Get the sum of a liste of number ---@param table table the table which you want to find if it contain the content @@ -39,22 +40,23 @@ end --- Get the table in form of a string ---@param table table the table which you want to transform into a string ---@return string string the string created from the table -function Table.toString(table) +function Table.toString(table, depth) + depth = depth or 2 local string = "{" for key, value in pairs(table) do - string = string .. key .. ":" - if (type(value) == "table") then - string = string .. Table.toString(value) - elseif type(value) == "boolean" then - if (value) then - string = string .. "true" + if (type(value) ~= "userdata" and depth > 0) then + if (type(value) == "table") then + if (value.is ~= nil) then + string = string .. "Object" + end + string = string .. Table.toString(value, depth - 1) + elseif (type(value) == "boolean") then + string = string .. Bools.toString(value) else - string = string .. "false" + string = string .. value end - else - string = string .. value + string = string .. "," end - string = string .. "," end return string .. "}" end