Removed repr dependency.
This commit is contained in:
parent
47771a79f9
commit
d37671a507
19
ldt.lua
19
ldt.lua
@ -1,6 +1,5 @@
|
||||
local C = require("curses")
|
||||
local re = require('re')
|
||||
local repr = require('repr')
|
||||
local ldb
|
||||
local AUTO = { }
|
||||
local PARENT = { }
|
||||
@ -129,7 +128,7 @@ do
|
||||
end
|
||||
end,
|
||||
setup_chstr = function(self, i)
|
||||
local chstr = _assert(self.chstrs[i], "Failed to find chstrs[" .. tostring(repr(i)) .. "]")
|
||||
local chstr = _assert(self.chstrs[i], "Failed to find chstrs[" .. tostring(i) .. "]")
|
||||
local x = 0
|
||||
for c = 1, #self.columns do
|
||||
local attr = self.colors[c](self, i)
|
||||
@ -665,7 +664,7 @@ make_lines = function(location, x, width)
|
||||
end
|
||||
return lines
|
||||
else
|
||||
local str = repr(x, 2)
|
||||
local str = tostring(x)
|
||||
if #str > width then
|
||||
str = str:sub(1, width - 3) .. '...'
|
||||
end
|
||||
@ -1118,13 +1117,6 @@ ldb = {
|
||||
table.insert(var_names, tostring(name))
|
||||
table.insert(values, value)
|
||||
stack_env[name] = value
|
||||
_ = [[ if type(value) == 'function'
|
||||
info = debug.getinfo(value, 'nS')
|
||||
--values\add_line(("function: %s @ %s:%s")\format(info.name or '???', info.short_src, info.linedefined))
|
||||
table.insert(values, repr(info))
|
||||
else
|
||||
table.insert(values, repr(value))
|
||||
]]
|
||||
end
|
||||
local var_y = pads.stack.y + pads.stack.height
|
||||
local var_x = 0
|
||||
@ -1225,7 +1217,12 @@ ldb = {
|
||||
else
|
||||
local ret = run_fn()
|
||||
if ret ~= nil then
|
||||
output = output .. ('= ' .. repr(ret) .. '\n')
|
||||
output = output .. '= '
|
||||
local bits = colored_repr(ret, SCREEN_W - 2, 4)
|
||||
for i = 1, #bits - 1, 2 do
|
||||
output = output .. bits[i]
|
||||
end
|
||||
output = output .. '\n'
|
||||
end
|
||||
local numlines = 0
|
||||
for nl in output:gmatch('\n') do
|
||||
|
19
ldt.moon
19
ldt.moon
@ -1,6 +1,5 @@
|
||||
C = require "curses"
|
||||
re = require 're'
|
||||
repr = require 'repr'
|
||||
local ldb
|
||||
AUTO = {} -- Singleton
|
||||
PARENT = {} -- Singleton
|
||||
@ -126,7 +125,7 @@ class Pad
|
||||
@width = @_width + 2
|
||||
|
||||
setup_chstr: (i)=>
|
||||
chstr = _assert(@chstrs[i], "Failed to find chstrs[#{repr i}]")
|
||||
chstr = _assert(@chstrs[i], "Failed to find chstrs[#{i}]")
|
||||
x = 0
|
||||
for c=1,#@columns
|
||||
attr = @colors[c](@, i)
|
||||
@ -417,7 +416,7 @@ make_lines = (location, x, width)->
|
||||
table.insert lines, {:location, '{}', TYPE_COLORS.table}
|
||||
return lines
|
||||
else
|
||||
str = repr(x,2)
|
||||
str = tostring(x)
|
||||
if #str > width
|
||||
str = str\sub(1,width-3)..'...'
|
||||
return {{:location, str, TYPE_COLORS[type(x)]}}
|
||||
@ -745,14 +744,6 @@ ldb = {
|
||||
table.insert(var_names, tostring(name))
|
||||
table.insert(values, value)
|
||||
stack_env[name] = value
|
||||
[[
|
||||
if type(value) == 'function'
|
||||
info = debug.getinfo(value, 'nS')
|
||||
--values\add_line(("function: %s @ %s:%s")\format(info.name or '???', info.short_src, info.linedefined))
|
||||
table.insert(values, repr(info))
|
||||
else
|
||||
table.insert(values, repr(value))
|
||||
]]
|
||||
|
||||
var_y = pads.stack.y + pads.stack.height
|
||||
var_x = 0
|
||||
@ -841,7 +832,11 @@ ldb = {
|
||||
else
|
||||
ret = run_fn!
|
||||
if ret != nil
|
||||
output ..= '= '..repr(ret)..'\n'
|
||||
output ..= '= '
|
||||
bits = colored_repr(ret, SCREEN_W-2, 4)
|
||||
for i=1,#bits-1,2
|
||||
output ..= bits[i]
|
||||
output ..= '\n'
|
||||
numlines = 0
|
||||
for nl in output\gmatch('\n') do numlines += 1
|
||||
stdscr\mvaddstr(SCREEN_H-numlines, 0, output)
|
||||
|
69
repr.lua
69
repr.lua
@ -1,69 +0,0 @@
|
||||
local re = require 're'
|
||||
local _quote_state = {}
|
||||
local max = math.max
|
||||
local _quote_patt = re.compile("(({'\n' / '\"' / \"'\" / '\\'}->mark_char) / (']' ({'='*}->mark_eq) (']' / !.)) / .)*",
|
||||
{mark_char=function(q)
|
||||
if q == "\n" or q == "\\" then
|
||||
_quote_state["'"] = false
|
||||
_quote_state['"'] = false
|
||||
if _quote_state.min_eq == nil then
|
||||
_quote_state.min_eq = 0
|
||||
end
|
||||
elseif q == "'" then
|
||||
_quote_state["'"] = false
|
||||
elseif q == '"' then
|
||||
_quote_state['"'] = false
|
||||
end
|
||||
end,
|
||||
mark_eq=function(eq)
|
||||
_quote_state.min_eq = max(_quote_state.min_eq or 0, #eq+1)
|
||||
end})
|
||||
local function repr(x, depth)
|
||||
-- Create a string representation of the object that is close to the lua code that will
|
||||
-- reproduce the object (similar to Python's "repr" function)
|
||||
depth = depth or 10
|
||||
if depth == 0 then return "..." end
|
||||
depth = depth - 1
|
||||
local x_type = type(x)
|
||||
if x_type == 'table' then
|
||||
local ret = {}
|
||||
local i = 1
|
||||
for k, v in pairs(x) do
|
||||
if k == i then
|
||||
ret[#ret+1] = repr(x[i], depth)
|
||||
i = i + 1
|
||||
elseif type(k) == 'string' and k:match("[_a-zA-Z][_a-zA-Z0-9]*") then
|
||||
ret[#ret+1] = k.."= "..repr(v,depth)
|
||||
else
|
||||
ret[#ret+1] = "["..repr(k,depth).."]= "..repr(v,depth)
|
||||
end
|
||||
end
|
||||
return "{"..table.concat(ret, ", ").."}"
|
||||
elseif x_type == 'string' then
|
||||
if x == "\n" then
|
||||
return "'\\n'"
|
||||
end
|
||||
_quote_state = {}
|
||||
_quote_patt:match(x)
|
||||
if _quote_state["'"] ~= false then
|
||||
return "\'" .. x .. "\'"
|
||||
elseif _quote_state['"'] ~= false then
|
||||
return "\"" .. x .. "\""
|
||||
else
|
||||
local eq = ("="):rep(_quote_state.min_eq or 0)
|
||||
-- BEWARE!!!
|
||||
-- Lua's parser and syntax are dumb, so Lua interprets x[[=[asdf]=]] as
|
||||
-- a function call to x (i.e. x("=[asdf]=")), instead of indexing x
|
||||
-- (i.e. x["asdf"]), which it obviously should be. This can be fixed by
|
||||
-- slapping spaces or parens around the [=[asdf]=].
|
||||
if x:sub(1, 1) == "\n" then
|
||||
return "["..eq.."[\n"..x.."]"..eq.."]"
|
||||
else
|
||||
return "["..eq.."["..x.."]"..eq.."]"
|
||||
end
|
||||
end
|
||||
else
|
||||
return tostring(x)
|
||||
end
|
||||
end
|
||||
return repr
|
Loading…
Reference in New Issue
Block a user