Mod migrations and version comparison functions.
local migration = require("__flib__.migration")
format_version(version[, format="%02d"]) | Normalize version strings for easy comparison. |
is_newer_version(old_version, current_version[, format=%02d]) | Check if current_version is newer than old_version. |
run(old_version, migrations[, format="%02d"]) | Run migrations against the given version. |
on_config_changed(event_data, migrations[, mod_name]) | Determine if migrations need to be run for this mod, then run them if needed. |
MigrationsTable |
Normalize version strings for easy comparison.
Parameters: Returns: Usage:
migration.format_version("1.10.1234", "%04d")
migration.format_version("3", "%02d")
Check if current_version is newer than old_version.
Parameters: Returns:
Run migrations against the given version.
Parameters:
Determine if migrations need to be run for this mod, then run them if needed.
Parameters:
-- In on_configuration_changed:
if migration.on_config_changed(e, migrations) then
-- run generic (non-init) migrations
rebuild_prototype_data()
else
-- run post-init setup
unlock_recipes_for_cheating_forces()
end
Dictionary string –> function. Each string is a version number, and each value is a function that will be run for that version.
{
["1.0.1"] = function()
global.foo = nil
for _, player_table in pairs(global.players) do
player_table.bar = "Lorem ipsum"
end
end,
["1.1.0"] = function()
global.foo = "bar"
end
}