-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.lua
67 lines (61 loc) · 1.63 KB
/
console.lua
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
local isArray = table.isArray or function(tab)
if (type(tab) ~= "table") then
return false
end
local length = #tab
for k, v in pairs(tab) do
if ((type(k) ~= "number") or (k > length)) then
return false
end
end
return true
end
local __console = console or {}
local function runTable(tab, space)
if (type(tab) == "number") then
return "" .. tab
end
if (type(tab) == "string") then
return '"' .. tab .. '"'
end
if (type(tab) == "boolean") then
return tab and "true" or "false"
end
if (type(tab) == "nil") then
return "no message"
end
if (type(tab) ~= "table") then
return "(" .. type(tab) .. ")"
end
if (type(space) ~= "string") then
space = ""
end
local newTab = {}
local childSpace = space .. " "
if (isArray(tab)) then
for k, v in ipairs(tab) do
table.insert(newTab, runTable(v, childSpace))
end
local childStr = table.concat(newTab, ", ")
if (string.len(childStr) > 50) then
newTab = {}
for k, v in ipairs(tab) do
table.insert(newTab, childSpace .. runTable(v, childSpace))
end
childStr = table.concat(newTab, ", \n")
return "[\n" .. childStr .. " \n" .. childSpace .. "]"
end
return space .. "[" .. childStr .. "]"
else
for k, v in pairs(tab) do
table.insert(newTab, childSpace .. k .. ": " .. runTable(v, childSpace))
end
return "{\n" .. table.concat(newTab, ", \n") .. " \n" .. space .. "}"
end
end
__console.log = __console.log or function(obj)
local js = runTable(obj)
print(js)
return js
end
console = __console