mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-29 16:24:35 +00:00
[added] tostring awareness for tablex.stringify
This commit is contained in:
parent
afd279f1db
commit
f214be9f59
@ -218,10 +218,16 @@ end
|
|||||||
--turn a table into a vaguely easy to read string
|
--turn a table into a vaguely easy to read string
|
||||||
--which is also able to be parsed by lua in most cases
|
--which is also able to be parsed by lua in most cases
|
||||||
function tablex.stringify(t)
|
function tablex.stringify(t)
|
||||||
if type(t) ~= "table" then
|
--if the input is not a table, or it has a tostring metamethod
|
||||||
|
--just use tostring
|
||||||
|
local mt = getmetatable(t)
|
||||||
|
if type(t) ~= "table" or mt and mt.__tostring then
|
||||||
return tostring(t)
|
return tostring(t)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--otherwise, collate into member chunks
|
||||||
local chunks = {}
|
local chunks = {}
|
||||||
|
--(tracking for already-seen elements from ipairs)
|
||||||
local seen = {}
|
local seen = {}
|
||||||
--sequential part first
|
--sequential part first
|
||||||
for i, v in ipairs(t) do
|
for i, v in ipairs(t) do
|
||||||
|
Loading…
Reference in New Issue
Block a user