Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function test.stringify(v, nobinary, dump, count)
- --Returns the string value of the parameter passed to it.
- --Works with nspickle() to display the contents of tables that contain binary data
- --Setting nobinary to true will strip binary data from the string form of tables.
- local fc = test.fgcolor['white']
- local function nspickle(tbl, nobinary, count)
- local msg = ''
- local indent = ''; if (dump) then indent = '\n'..string.rep('\t', count-1) end
- local idx = ''
- local n = 0
- for i, v in ipairs(tbl) do
- local tv = type(v)
- if (not (nobinary and (tv == 'function' or tv == 'userdata' or tv == 'thread'))) then
- if (dump) then idx = '['..tostring(i)..']=' else idx = '' end
- msg = msg..indent..idx..test.stringify(v, nobinary, dump, count)..','
- n = i
- else
- break
- end
- end
- msg = msg:gsub(',$', ';')
- for k, v in pairs(tbl) do
- local tk = type(k)
- local tv = type(v)
- if (tk ~= 'number' or (tk == 'number' and (k < 1 or k > n))) then
- if (tk == 'number') then
- k = '['..k..']'
- elseif (tk == 'string' and k:match('[^%w_]')) then
- k = '["'..k..'"]'
- end
- if (not (nobinary and (tv == 'function' or tv == 'userdata' or tv == 'thread'))) then
- msg = msg..indent..tostring(k)..'='..test.stringify(v, nobinary, dump, count)..','
- end
- end
- end
- msg = msg:gsub('[,;]$', '')
- return msg
- end
- local t = type(v)
- if (t == 'table') then
- count = (count or 0) + 1
- local pre, post = '{', '}'
- if (dump) then
- --pre = string.rep('\t', count - 2)..'{'
- post = '\n'..string.rep('\t', count-2)..'}'
- end
- v = pre..nspickle(v, nobinary, count)..post
- count = count - 1
- if (count == 0) then v = v:gsub('^{(.*)}$', '%1') end
- elseif (t == 'string') then v = '"'..v..'"'
- else v = tostring(v)
- end
- return v
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement