From f214be9f593c79a54cca61e09cff8aeccbbecc19 Mon Sep 17 00:00:00 2001 From: Max Cahill <1bardesign@gmail.com> Date: Wed, 8 Apr 2020 21:10:24 +1000 Subject: [PATCH] [added] tostring awareness for tablex.stringify --- tablex.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tablex.lua b/tablex.lua index 676687a..7344168 100644 --- a/tablex.lua +++ b/tablex.lua @@ -218,10 +218,16 @@ end --turn a table into a vaguely easy to read string --which is also able to be parsed by lua in most cases 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) end + + --otherwise, collate into member chunks local chunks = {} + --(tracking for already-seen elements from ipairs) local seen = {} --sequential part first for i, v in ipairs(t) do