Update utils.lua
This commit is contained in:
@@ -49,6 +49,34 @@ function get_key(tab, val)
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function concat_tables(t1, t2)
|
||||||
|
for _,v in ipairs(t2) do
|
||||||
|
table.insert(t1, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function serialize_table(tab, ind)
|
||||||
|
ind = ind and (ind .. " ") or " "
|
||||||
|
local nl = "\n"
|
||||||
|
local str = "{" .. nl
|
||||||
|
for k, v in pairs(tab) do
|
||||||
|
local pr = (type(k)=="string") and ("[\"" .. k .. "\"] = ") or ""
|
||||||
|
str = str .. ind .. pr
|
||||||
|
if type(v) == "table" then
|
||||||
|
str = str .. serialize(v, ind) .. ","
|
||||||
|
elseif type(v) == "string" then
|
||||||
|
str = str .. "\"" .. tostring(v) .. "\","
|
||||||
|
elseif type(v) == "number" or type(v) == "boolean" then
|
||||||
|
str = str .. tostring(v) .. ","
|
||||||
|
else
|
||||||
|
str = str .. "[[" .. tostring(v) .. "]],"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
str = str:gsub(".$","")
|
||||||
|
str = str .. nl .. ind .. "}"
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
|
||||||
function round(x, n)
|
function round(x, n)
|
||||||
local n = math.pow(10, n or 0)
|
local n = math.pow(10, n or 0)
|
||||||
local x = x * n
|
local x = x * n
|
||||||
@@ -66,3 +94,4 @@ function use(module, ...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user