Page 1 of 1

LUA warnings on older mods

Posted: Mon Jul 06, 2026 1:49 pm
by thekabal
I'm working to update older mods for 2.1, and have found a number of instances of warnings in luacheck like:

mutating non-standard global variable data
accessing undefined variable data

In both cases, the relevant lines look like:


data.raw["cargo-pod"]["cargo-pod"].created_effect = {
...
data:extend({

My understanding of Lua leads me to think that these mods are referencing the global variable "data", and changing the code to directly reference global variables clears the error:


_G.data.raw
...
_G.data.extend


But it feels incorrect to do everything in globals directly. I read https://lua-api.factorio.com/latest/aux ... orage.html and I'm wondering if I could instead shift these mods to use the storage variable instead? Would that be better? What would that look like?

Re: LUA warnings on older mods

Posted: Mon Jul 06, 2026 2:02 pm
by robot256
data.raw and data:extend always (and only) exist in the Data stage during game startup. They are defined by the game engine before the mod's data.lua runs inside the shared Data stage Lua context, and persist while base and all mods run data.lua, data-updates.lua, and data-final-fixes.lua. Luacheck is giving you false warning because it doesn't know that. The code is correct and changing it to _G.data would just add clutter.

storage only exists during the Control stage, in the per-mod runtime sandbox context. It is defined by the game engine when the mod's runtime context is created for control.lua. It is not correct to use storage during the Data stage.

Re: LUA warnings on older mods

Posted: Mon Jul 06, 2026 2:12 pm
by thekabal
Fantastic detail and explanation! Thank you very much!