From adfab5b79dc9652feb1ab9f5f4972f12ea7036df Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 25 Mar 2018 15:38:48 -0700 Subject: [PATCH] Hardening. --- ldt.lua | 28 ++++++++++++++++------------ ldt.moon | 24 ++++++++++++++---------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/ldt.lua b/ldt.lua index 7526833..95a3c50 100644 --- a/ldt.lua +++ b/ldt.lua @@ -115,7 +115,7 @@ do end end, setup_chstr = function(self, i) - local chstr = self.chstrs[i] + local chstr = assert(self.chstrs[i], "Failed to find chstrs[" .. tostring(repr(i)) .. "]") local x = 0 for c = 1, #self.columns do local attr = self.colors[c](self, i) @@ -374,6 +374,7 @@ err_hand = function(err) end ldb = { run_debugger = function(err_msg) + err_msg = err_msg or '' local stdscr = C.initscr() local SCREEN_H, SCREEN_W = stdscr:getmaxyx() C.cbreak() @@ -486,7 +487,10 @@ ldb = { end end for line, _ in pairs(err_lines) do - pads.src:setup_chstr(tonumber(line:match("[^:]*:(%d*).*"))) + local _filename, i = line:match("([^:]*):(%d*).*") + if _filename == filename and tonumber(i) then + pads.src:setup_chstr(tonumber(i)) + end end pads.src:select(line_no) return @@ -576,30 +580,30 @@ ldb = { local value_str = repr(value, 3) local mt = getmetatable(value) if mt then - if mt.__class and mt.__class.__name then - type_str = mt.__class.__name - elseif value.__base and value.__name then - type_str = "class " .. tostring(value.__name) + if rawget(mt, '__class') and rawget(rawget(mt, '__class'), '__name') then + type_str = rawget(rawget(mt, '__class'), '__name') + elseif rawget(value, '__base') and rawget(value, '__name') then + type_str = "class " .. tostring(rawget(value, '__name')) else type_str = 'table with metatable' end - if mt.__tostring then + if rawget(mt, '__tostring') then value_str = tostring(value) else - if value.__base and value.__name then - value = value.__base - value_str = repr(value, 2) + if rawget(value, '__base') and rawget(value, '__name') then + value = rawget(value, '__base') + value_str = repr(value, 3) end if #value_str >= value_w - 2 then local key_repr key_repr = function(k) - return type(k) == 'string' and k or "[" .. tostring(repr(k, 1)) .. "]" + return type(k) == 'string' and k or "[" .. tostring(repr(k, 2)) .. "]" end value_str = table.concat((function() local _accum_0 = { } local _len_0 = 1 for k, v in pairs(value) do - _accum_0[_len_0] = tostring(key_repr(k)) .. " = " .. tostring(repr(v, 1)) + _accum_0[_len_0] = tostring(key_repr(k)) .. " = " .. tostring(repr(v, 2)) _len_0 = _len_0 + 1 end return _accum_0 diff --git a/ldt.moon b/ldt.moon index 6364976..0d75e29 100644 --- a/ldt.moon +++ b/ldt.moon @@ -113,7 +113,7 @@ class Pad @width = @_width + 2 setup_chstr: (i)=> - chstr = @chstrs[i] + chstr = assert(@chstrs[i], "Failed to find chstrs[#{repr i}]") x = 0 for c=1,#@columns attr = @colors[c](@, i) @@ -239,6 +239,7 @@ err_hand = (err)-> ldb = { run_debugger: (err_msg)-> + err_msg or= '' stdscr = C.initscr! SCREEN_H, SCREEN_W = stdscr\getmaxyx! @@ -329,7 +330,9 @@ ldb = { elseif i == @selected then color("reverse") else color() for line,_ in pairs(err_lines) - pads.src\setup_chstr(tonumber(line\match("[^:]*:(%d*).*"))) + _filename, i = line\match("([^:]*):(%d*).*") + if _filename == filename and tonumber(i) + pads.src\setup_chstr(tonumber(i)) pads.src\select(line_no) return else @@ -398,18 +401,19 @@ ldb = { value_str = repr(value, 3) mt = getmetatable(value) if mt - type_str = if mt.__class and mt.__class.__name then mt.__class.__name - elseif value.__base and value.__name then "class #{value.__name}" + type_str = if rawget(mt, '__class') and rawget(rawget(mt, '__class'), '__name') + rawget(rawget(mt, '__class'), '__name') + elseif rawget(value, '__base') and rawget(value, '__name') then "class #{rawget(value,'__name')}" else 'table with metatable' - if mt.__tostring + if rawget(mt, '__tostring') value_str = tostring(value) else - if value.__base and value.__name - value = value.__base - value_str = repr(value, 2) + if rawget(value, '__base') and rawget(value, '__name') + value = rawget(value, '__base') + value_str = repr(value, 3) if #value_str >= value_w-2 - key_repr = (k)-> type(k) == 'string' and k or "[#{repr(k,1)}]" - value_str = table.concat ["#{key_repr k} = #{repr v,1}" for k,v in pairs(value)], "\n \n" + key_repr = (k)-> type(k) == 'string' and k or "[#{repr(k,2)}]" + value_str = table.concat ["#{key_repr k} = #{repr v,2}" for k,v in pairs(value)], "\n \n" pads.values = Pad "(D)ata [#{type_str}]",var_y,value_x,pads.vars.height,value_w, wrap_text(value_str, value_w-2), (i)=>color("cyan bold")