Page 1 of 1

Accidental Gloabals

Posted: Thu Dec 08, 2022 10:45 am
by KiwiHawk
I was running a check on my mods, looking for variables that had accidentally been declared as globals. I found three in the base game:

common\Factorio\data\core\lualib\util.lua

Code: Select all

-- This function takes 2 icons tables, and adds the second to the first, but applies scale, shift and tint to the entire second set.
-- This allows you to manipulate the entire second icons table in the same way as you would manipulate a single icon when adding to the icons table.
function util.combine_icons(icons1, icons2, inputs, default_icon_size)
  scale = inputs.scale or 1
  shift = inputs.shift or {0, 0}
  tint = inputs.tint or {r = 1, g = 1, b = 1, a = 1}
I believe variables scale, shift, and tint should all be declared as local. I know this is minor but it would allow my test to pass!

Re: Accidental Gloabals

Posted: Thu Dec 08, 2022 10:51 am
by KiwiHawk
I used this code to do the checks:

Code: Select all

setmetatable(_G, {
  __newindex = function (_, n)
    error("attempt to write to undeclared variable "..n)
  end,
  __index = function (_, n)
    error("attempt to read undeclared variable "..n)
  end,
})

Re: Accidental Gloabals

Posted: Thu Dec 08, 2022 9:14 pm
by InappropriatePenguin
It would be funny if fixing this were to break some mods :D

Re: Accidental Gloabals

Posted: Thu May 16, 2024 12:25 pm
by KiwiHawk
This has been fixed. Thread can be moved to implemented?