From bff12f4742fea320f3b49e5bd45d7c81cf2b20ac Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 6 Apr 2018 18:35:44 -0700 Subject: [PATCH] Added support for browsing any object that supports __pairs iteration and also included its __tostring if one is provided. --- ldt.lua | 28 ++++++++++++++++++++++++++++ ldt.moon | 11 +++++++++++ 2 files changed, 39 insertions(+) diff --git a/ldt.lua b/ldt.lua index 626b955..79391a8 100644 --- a/ldt.lua +++ b/ldt.lua @@ -668,6 +668,34 @@ make_lines = function(location, x, width) end return lines else + if getmetatable(x) and getmetatable(x).__pairs then + local lines = make_lines(location, (function() + local _tbl_0 = { } + for k, v in pairs(x) do + _tbl_0[k] = v + end + return _tbl_0 + end)(), width) + if getmetatable(x).__tostring then + local s_lines = { } + local _list_0 = line_matcher:match(tostring(x)) + for _index_0 = 1, #_list_0 do + local line = _list_0[_index_0] + local wrapped = wrap_text(line, width) + for i, subline in ipairs(wrapped) do + table.insert(s_lines, { + location = location, + subline, + Color('yellow') + }) + end + end + for i = 1, #s_lines do + table.insert(lines, i, s_lines[i]) + end + end + return lines + end local str = tostring(x) if #str > width then str = str:sub(1, width - 3) .. '...' diff --git a/ldt.moon b/ldt.moon index c82b6cd..47a3b97 100644 --- a/ldt.moon +++ b/ldt.moon @@ -413,6 +413,17 @@ make_lines = (location, x, width)-> table.insert lines, {:location, '{}', TYPE_COLORS.table} return lines else + if getmetatable(x) and getmetatable(x).__pairs + lines = make_lines(location, {k,v for k,v in pairs(x)}, width) + if getmetatable(x).__tostring + s_lines = {} + for line in *line_matcher\match(tostring(x)) + wrapped = wrap_text(line, width) + for i,subline in ipairs(wrapped) + table.insert(s_lines, {:location, subline, Color('yellow')}) + for i=1,#s_lines + table.insert(lines, i, s_lines[i]) + return lines str = tostring(x) if #str > width str = str\sub(1,width-3)..'...'