-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebug.lua
More file actions
46 lines (42 loc) · 989 Bytes
/
debug.lua
File metadata and controls
46 lines (42 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
-- require string_encode
-- require binary/bits_from
function debug(t,depth,indent)
local depth = depth and depth or 2
local tab = (indent and indent or '')
local ty = type(t)
if ty == 'table' then
local s = ''
for k,v in pairs(t) do
if depth > 0 then
s = s..'\n'..tab..k..':'..debug(v,depth-1,tab..' ')
else
s = s..'\n'..tab..k..':MAXDEPTH'
end
end
return s
elseif ty == 'string' or ty == 'number' then
return tab..t
elseif ty == 'boolean' then
return tab..(t and 'true' or 'false')
else
return '('..ty..')'
end
end
function debugp(t) printh(debug(t)) end
function bits_as_string(bits)
local string = ''
for bit in all(bits) do
string = string..(bit and 1 or 0)
end
return string
end
function compress(size,table)
for k,v in pairs(table) do
table[k] = bits_to_string(bits_from(size,v))
end
return table
end
-- expect debug
-- expect debugp
-- expect bits_as_string
-- expect compress