feat: some parsing improvement

This commit is contained in:
Kazhnuz 2021-08-31 10:57:24 +02:00
parent 70f1fe21e9
commit 3c94f9c1c6
3 changed files with 29 additions and 12 deletions

View file

@ -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

View file

@ -21,6 +21,6 @@ function String.split(pString, pPattern)
table.insert(Table, cap) table.insert(Table, cap)
end end
return Table return Table
end end
return String return String

View file

@ -22,6 +22,7 @@
]] ]]
local Table = {} local Table = {}
local Bools = require "birb.utils.bools"
--- Get the sum of a liste of number --- Get the sum of a liste of number
---@param table table the table which you want to find if it contain the content ---@param table table the table which you want to find if it contain the content
@ -39,23 +40,24 @@ end
--- Get the table in form of a string --- Get the table in form of a string
---@param table table the table which you want to transform into a string ---@param table table the table which you want to transform into a string
---@return string string the string created from the table ---@return string string the string created from the table
function Table.toString(table) function Table.toString(table, depth)
depth = depth or 2
local string = "{" local string = "{"
for key, value in pairs(table) do for key, value in pairs(table) do
string = string .. key .. ":" if (type(value) ~= "userdata" and depth > 0) then
if (type(value) == "table") then if (type(value) == "table") then
string = string .. Table.toString(value) if (value.is ~= nil) then
elseif type(value) == "boolean" then string = string .. "Object"
if (value) then
string = string .. "true"
else
string = string .. "false"
end end
string = string .. Table.toString(value, depth - 1)
elseif (type(value) == "boolean") then
string = string .. Bools.toString(value)
else else
string = string .. value string = string .. value
end end
string = string .. "," string = string .. ","
end end
end
return string .. "}" return string .. "}"
end end