forked from thehunmonkgroup/jester
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.lua
More file actions
33 lines (33 loc) · 1.14 KB
/
debug.lua
File metadata and controls
33 lines (33 loc) · 1.14 KB
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
--[[
Dumps values to console, with recursive option for tables.
]]
function debug_dump(var, recursive, prefix)
local key, value
prefix = prefix or ""
if type(var) == "table" then
for k, v in pairs(var) do
if type(v) == "string" or type(v) == "number" or type(v) == "boolean" then
value = tostring(v)
else
value = type(v)
end
if type(k) == "string" or type(k) == "number" or type(k) == "boolean" then
key = tostring(k)
else
key = type(k)
end
-- Exclude possibly infinitely recursive keys.
if k ~= "_M" and k ~= "__index" then
jester.log(string.format([[%s%s, value: %s]], prefix, key, value), "JESTER VAR DUMP")
-- Tables get optional recursive treatment.
if recursive and type(v) == "table" then
debug_dump(v, recursive, prefix .. "[" .. key .. "]")
end
end
end
elseif type(var) == "string" or type(var) == "number" or type(var) == "boolean" then
jester.log(string.format([[value: %s]], tostring(var)), "JESTER VAR DUMP")
else
jester.log(string.format([[value: %s]], type(var)), "JESTER VAR DUMP")
end
end