-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.lua
54 lines (49 loc) · 1.39 KB
/
Logger.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
-- Logger.lua
-- Copyright OxidaneDev 2024
-- This module imitates "console.log" from javascript
-- Usage: require("Logger").log("Hello World", 2, {Hi = "Hello"})
local console = {}
console.__index = console
function console.log(...)
local printValue
local function printTable(t, indent)
indent = indent or ""
if type(t) ~= "table" then
io.write(tostring(t))
return
end
io.write("{\n")
for k, v in pairs(t) do
io.write(indent, " ", tostring(k), ": ")
if type(v) == "table" then
printTable(v, indent .. " ")
else
printValue(v)
end
io.write(",\n")
end
io.write(indent, "}")
end
printValue = function (value)
if type(value) == "string" then
io.write("\27[32m\"" .. tostring(value) .. "\"\27[0m")
elseif type(value) == "number" then
io.write("\27[33m" .. tostring(value) .. "\27[0m")
else
io.write(tostring(value))
end
end
local args = {...}
for i = 1, #args do
if type(args[i]) == "table" then
printTable(args[i])
else
printValue(args[i])
end
if i < #args then
io.write(" ")
end
end
io.write("\n")
end
return console