1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-26 03:52:00 +02:00
RedMew/utils/dump_env.lua
RedRafe 26e1c28dc0
Factorio 2.0 update (#1436)
* Init Factorio 2.0 update

* add credits

* fix test module

* I know luackeck, I know

* Fixes

* Fix bad event.player_index handling

* Hotfixes

* Remove all filter inserters

* Migrate removed items

* Deprecating spidertron control and landfill features
2024-10-22 20:22:35 +01:00

35 lines
1.1 KiB
Lua

-- 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.
-- dependencies
local table = require 'utils.table'
local Event = require 'utils.event'
-- localized functions
local inspect = table.inspect
-- local constants
local filename = 'env_dump.lua'
-- 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)
game.tick_paused = true
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)
helpers.write_file(filename, s)
game.print('_ENV dumped into ' .. filename)
else
game.print('_ENV not dumped, dump_string was nil')
end
game.print('Game is paused. Use /c game.tick_paused = false to resume play')
end
Event.add(defines.events.on_player_joined_game, player_joined)