Minetest-WorldEditAdditions/worldeditadditions/utils/tables/table_tostring.lua

21 lines
705 B
Lua
Raw Normal View History

--- Returns the key value pairs in a table as a single string
-- @param tbl table input table
-- @param sep string key value seperator
-- @param new_line string key value pair delimiter
-- @return string concatenated table pairs
local function table_tostring(tbl, sep, new_line)
if type(sep) ~= "string" then sep = ": " end
if type(new_line) ~= "string" then new_line = ", " end
local ret = {}
if type(tbl) ~= "table" then return "Error: input not table!" end
for key,value in pairs(tbl) do
2021-06-30 18:59:19 +00:00
table.insert(ret,key)
table.insert(ret,sep)
table.insert(ret,value)
table.insert(ret,new_line)
end
2021-06-30 18:59:19 +00:00
return table.concat(ret,"")
end
return table_tostring