From fd088d9dcf826396db5b00b87259cb0281ca8914 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Fri, 18 Feb 2022 14:51:40 +0100 Subject: [PATCH] feat(debug): allow for more types to be sent to the debug --- server/debug.lua | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/server/debug.lua b/server/debug.lua index bcdd919..9b4b3b2 100644 --- a/server/debug.lua +++ b/server/debug.lua @@ -1,38 +1,39 @@ local function tPrint(tbl, indent) indent = indent or 0 - for k, v in pairs(tbl) do - local tblType = type(v) - local formatting = ("%s ^3%s:^0"):format(string.rep(" ", indent), k) + if type(tbl) == 'table' then + for k, v in pairs(tbl) do + local tblType = type(v) + local formatting = ("%s ^3%s:^0"):format(string.rep(" ", indent), k) - if tblType == "table" then - print(formatting) - tPrint(v, indent + 1) - elseif tblType == 'boolean' then - print(("%s^1 %s ^0"):format(formatting, v)) - elseif tblType == "function" then - print(("%s^9 %s ^0"):format(formatting, v)) - elseif tblType == 'number' then - print(("%s^5 %s ^0"):format(formatting, v)) - elseif tblType == 'string' then - print(("%s ^2'%s' ^0"):format(formatting, v)) - else - print(("%s^2 %s ^0"):format(formatting, v)) + if tblType == "table" then + print(formatting) + tPrint(v, indent + 1) + elseif tblType == 'boolean' then + print(("%s^1 %s ^0"):format(formatting, v)) + elseif tblType == "function" then + print(("%s^9 %s ^0"):format(formatting, v)) + elseif tblType == 'number' then + print(("%s^5 %s ^0"):format(formatting, v)) + elseif tblType == 'string' then + print(("%s ^2'%s' ^0"):format(formatting, v)) + else + print(("%s^2 %s ^0"):format(formatting, v)) + end end + else + print(("%s ^0%s"):format(string.rep(" ", indent), tbl)) end end -RegisterServerEvent('QBCore:DebugSomething', function(table, indent) +RegisterServerEvent('QBCore:DebugSomething', function(tbl, indent) local resource = GetInvokingResource() or "qb-core" - print(('\x1b[4m\x1b[36m[ %s : DEBUG]\x1b[0m'):format(resource)) - - tPrint(table, indent) - + tPrint(tbl, indent) print('\x1b[4m\x1b[36m[ END DEBUG ]\x1b[0m') end) -function QBCore.Debug(table, indent) - TriggerEvent('QBCore:DebugSomething', table, indent) +function QBCore.Debug(tbl, indent) + TriggerEvent('QBCore:DebugSomething', tbl, indent) end function QBCore.ShowError(resource, msg)