diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-12 16:33:11 -0800 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-12 16:33:11 -0800 |
| commit | 6b09187899e86eabc25ed2ff96f4c2e51f130c00 (patch) | |
| tree | 327179a15dfbc0bf11ad293097252ea4bd241b69 /utils.lua | |
| parent | e09f05a50cdb699029e8a4d5bafcfaade34157fd (diff) | |
Switched to use load() with environment table instead of passing in
nomsu to everything. This has some nice code cleanliness benefits.
Diffstat (limited to 'utils.lua')
| -rw-r--r-- | utils.lua | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -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, ", ").."}" |
