From b6fd5f917d994a9cee9dc9e25b28c0c8f8795a42 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 24 Oct 2017 11:56:04 +0100 Subject: [PATCH] Lib edit --- locale/ExpGaming-Core/ExpGaming - Lib.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/locale/ExpGaming-Core/ExpGaming - Lib.lua b/locale/ExpGaming-Core/ExpGaming - Lib.lua index f2075674..3b5a6e18 100644 --- a/locale/ExpGaming-Core/ExpGaming - Lib.lua +++ b/locale/ExpGaming-Core/ExpGaming - Lib.lua @@ -67,6 +67,18 @@ function table.tostring( tbl ) end return "{" .. table.concat( result, "," ) .. "}" end +-- converts a table to json and logs it to a file +function json_log(table,no_log) + local json = '{' + for key,value in pairs(table) do + if type(value) == 'table' then value = json_log(value,true) end + if type(value) == 'string' then json = json..'"'..key..'"="'..value..'",' end + elseif type(value) == 'number' then json = json..'"'..key..'"='..value..',' + else json = json..'"'..key..'"=null,' end + end + if no_log then return json:sub(-1)..'}' + else game.write_file('multi.log',json:sub(-1)..'}\n', true, 0) end +end -- allows a simple way to debug code; idenitys = {'string1','string2'}; string will be writen to file; no_trigger dissables the trigger useful for on_tick events function debug_write(idenitys,string,no_trigger) if global.exp_core.debug.state then