From d83bcd31864ad44ac36216081302d901eed4d4b7 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Sat, 26 Oct 2019 00:05:52 +0200 Subject: [PATCH] update debug func --- utils/debug/_g_view.lua | 1 - utils/debug/command.lua | 77 ++++++++++++++++++++++++++++++++++++++++- utils/debug/model.lua | 2 +- 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/utils/debug/_g_view.lua b/utils/debug/_g_view.lua index b996e7e5..dfbe0a7a 100644 --- a/utils/debug/_g_view.lua +++ b/utils/debug/_g_view.lua @@ -76,7 +76,6 @@ function Public.show(container) end local right_panel = main_flow.add {type = 'text-box', name = right_panel_name} - right_panel.word_wrap = true right_panel.read_only = true right_panel.selectable = true diff --git a/utils/debug/command.lua b/utils/debug/command.lua index 2f92cbff..4fa663ce 100644 --- a/utils/debug/command.lua +++ b/utils/debug/command.lua @@ -1,9 +1,15 @@ local DebugView = require 'utils.debug.main_view' +local Model = require 'model' + +local loadstring = loadstring +local pcall = pcall +local dump = Model.dump +local log = log commands.add_command( 'debug', 'Opens the debugger', - function(_, player) + function(_) local player = game.player local p if player then @@ -18,3 +24,72 @@ commands.add_command( DebugView.open_dubug(player) end ) + +commands.add_command( + 'dump-log', + 'Dumps value to log', + function(args) + local player = game.player + local p + if player then + p = player.print + if not player.admin then + p('Only admins can use this command.') + return + end + else + p = player.print + end + if args.parameter == nil then return end + local func, err = loadstring('return ' .. args.parameter) + + if not func then + p(err) + return + end + + local suc, value = pcall(func) + + if not suc then + p(value) + return + end + + log(dump(value)) + end +) + +commands.add_command( + 'dump-file', + 'Dumps value to dump.lua', + function(args) + local player = game.player + local p + if player then + p = player.print + if not player.admin then + p('Only admins can use this command.') + return + end + else + p = player.print + end + if args.parameter == nil then return end + local func, err = loadstring('return ' .. args.parameter) + + if not func then + p(err) + return + end + + local suc, value = pcall(func) + + if not suc then + p(value) + return + end + + value = dump(value) + game.write_file('dump.lua', value, false) + end +) \ No newline at end of file diff --git a/utils/debug/model.lua b/utils/debug/model.lua index bd746759..90be49de 100644 --- a/utils/debug/model.lua +++ b/utils/debug/model.lua @@ -71,7 +71,6 @@ local function inspect_process(item) return concat(luaEntity) elseif obj_type == 'LuaGuiElement' then local name = item.name - if luaGuiElement[2] == nil then return end luaGuiElement[2] = gui_names[name] or name or 'nil' return concat(luaGuiElement) @@ -88,6 +87,7 @@ function Public.dump(data) return inspect(data, inspect_options) end local dump = Public.dump +_G.dump = dump function Public.dump_ignore_builder(ignore) local function process(item)