1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-03-11 14:49:59 +02:00

Add dump_env (#558)

* Add dump_env

* Create new global for env dump
This commit is contained in:
Matthew 2018-12-22 03:42:19 -05:00 committed by Valansch
parent 50fbecf555
commit 8d3c32e932
4 changed files with 32 additions and 1 deletions

View File

@ -56,7 +56,7 @@ local STD_BASE_CONTROL = 'lua52c+factorio+factorio_control+factorio_defines+fact
--[Assume Factorio Control stage as default]--
-------------------------------------------------------------------------------
std = STD_CONTROL
globals = {'print', 'math', 'table', '_DEBUG', '_CHEATS', 'ServerCommands'} -- RedMew-specific globals
globals = {'print', 'math', 'table', '_DEBUG', '_CHEATS', '_DUMP_ENV', 'ServerCommands'} -- RedMew-specific globals
max_line_length = LINE_LENGTH
not_globals = NOT_GLOBALS

View File

@ -1,5 +1,6 @@
_DEBUG = false
_CHEATS = false
_DUMP_ENV = false
local market_item = 'coin'
global.config = {

View File

@ -93,3 +93,6 @@ end
if config.camera.enabled then
require 'features.gui.camera'
end
if _DUMP_ENV then
require 'utils.dump_env'
end

27
utils/dump_env.lua Normal file
View File

@ -0,0 +1,27 @@
-- A small debugging tool that writes the contents of _ENV to a file when the game loads.
-- Useful for ensuring you get the same information when loading
-- the reference and desync levels in desync reports.
require 'utils.table'
local Event = require 'utils.event'
local filename = 'env_dump.lua'
local inspect = table.inspect
-- Removes metatables and the package table
local filter = function(item, path)
if path[#path] ~= inspect.METATABLE and item ~= 'package' then
return item
end
end
local function player_joined(event)
local dump_string = inspect(_ENV, {process = filter})
if dump_string then
local s = string.format('tick on join: %s\n%s', event.tick, dump_string)
game.write_file(filename, s)
game.print('_ENV dumped into ' .. filename)
else
game.print('_ENV not dumped, dump_string was nil')
end
end
Event.add(defines.events.on_player_joined_game, player_joined)