lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Paul,

Thanks for your work on serpent. The following might be a handy feature,
allowing the caller to specify a max level when dumping an object. This comes
in handy for debugging when you're not interested in stuff deeply nested in
tables: http://pastebin.com/1AVwNwNq

Ico

--- serpent.lua.org	2012-06-13 15:04:36.894692373 +0200
+++ serpent.lua	2012-06-13 15:04:39.126693082 +0200
@@ -14,6 +14,7 @@
   local name, indent, fatal = opts['name'], opts['indent'], opts['fatal']
   local sparse, nocode, custom = opts['sparse'], opts['nocode'], opts['custom']
   local huge, space = not opts['nohuge'], (opts['compact'] and '' or ' ')
+  local maxlevel = opts['maxlevel']
   local seen, sref = {}, {}
   local function gensym(val) return tostring(val):gsub("[^%w]","") end
   local function safestr(s) return type(s) == "number" and (huge and snum[tostring(s)] or s)
@@ -51,6 +52,7 @@
         "loadstring("..safestr(res)..",'@serialized')"..comment(t))
       return tag..(func or globerr(t))
     elseif ttype == "table" then
+      if level >= maxlevel then return '{}'..comment('maxlevel') end
       seen[t] = spath
       if next(t) == nil then return tag..'{}'..comment(t) end -- table empty
       local maxn, o, out = #t, {}, {}
-- 
:wq
^X^Cy^K^X^C^C^C^C