From 6b09187899e86eabc25ed2ff96f4c2e51f130c00 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 12 Jan 2018 16:33:11 -0800 Subject: Switched to use load() with environment table instead of passing in nomsu to everything. This has some nice code cleanliness benefits. --- utils.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'utils.lua') diff --git a/utils.lua b/utils.lua index 1e77965..9dee6d7 100644 --- a/utils.lua +++ b/utils.lua @@ -42,9 +42,12 @@ local _quote_patt = re.compile("(({'\n' / '\"' / \"'\" / '\\'}->mark_char) / ('] mark_eq=function(eq) _quote_state.min_eq = max(_quote_state.min_eq or 0, #eq+1) end}) -local function repr(x) +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 if getmetatable(x) then @@ -55,12 +58,12 @@ local function repr(x) local i = 1 for k, v in pairs(x) do if k == i then - ret[#ret+1] = repr(x[i]) + 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) + ret[#ret+1] = k.."= "..repr(v,depth) else - ret[#ret+1] = "["..repr(k).."]= "..repr(v) + ret[#ret+1] = "["..repr(k,depth).."]= "..repr(v,depth) end end return "{"..table.concat(ret, ", ").."}" -- cgit v1.2.3