mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-26 00:53:00 +00:00
Update table_tostring.lua
This commit is contained in:
parent
484b7532eb
commit
f709d12b75
1 changed files with 8 additions and 11 deletions
|
@ -4,17 +4,14 @@
|
||||||
-- @param new_line string key value pair delimiter
|
-- @param new_line string key value pair delimiter
|
||||||
-- @return string concatenated table pairs
|
-- @return string concatenated table pairs
|
||||||
local function table_tostring(tbl, sep, new_line)
|
local function table_tostring(tbl, sep, new_line)
|
||||||
if type(sep) ~= "string" then sep = ": " end
|
if type(sep) ~= "string" then sep = ": " end
|
||||||
if type(new_line) ~= "string" then new_line = ", " end
|
if type(new_line) ~= "string" then new_line = ", " end
|
||||||
local ret = {}
|
local ret = {}
|
||||||
if type(tbl) ~= "table" then return "Error: input not table!" end
|
if type(tbl) ~= "table" then return "Error: input not table!" end
|
||||||
for key,value in pairs(tbl) do
|
for key,value in pairs(tbl) do
|
||||||
table.insert(ret,key)
|
table.insert(ret,tostring(key) .. sep .. tostring(value) .. new_line)
|
||||||
table.insert(ret,sep)
|
end
|
||||||
table.insert(ret,value)
|
return table.concat(ret,"")
|
||||||
table.insert(ret,new_line)
|
|
||||||
end
|
|
||||||
return table.concat(ret,"")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return table_tostring
|
return table_tostring
|
||||||
|
|
Loading…
Reference in a new issue