Accidental Gloabals

User avatar
KiwiHawk
Filter Inserter
Filter Inserter
Posts: 270
Joined: Thu Jul 05, 2018 9:48 am
Contact:

Accidental Gloabals

Post 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!
Dev for Bob's mods, Angel's mods, Helmod, Sea Block, Circuit Processing, Science Cost Tweaker.

Buy me a coffee

User avatar
KiwiHawk
Filter Inserter
Filter Inserter
Posts: 270
Joined: Thu Jul 05, 2018 9:48 am
Contact:

Re: Accidental Gloabals

Post 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,
})
Dev for Bob's mods, Angel's mods, Helmod, Sea Block, Circuit Processing, Science Cost Tweaker.

Buy me a coffee

InappropriatePenguin
Inserter
Inserter
Posts: 29
Joined: Mon Sep 13, 2021 6:53 pm
Contact:

Re: Accidental Gloabals

Post by InappropriatePenguin »

It would be funny if fixing this were to break some mods :D

User avatar
KiwiHawk
Filter Inserter
Filter Inserter
Posts: 270
Joined: Thu Jul 05, 2018 9:48 am
Contact:

Re: Accidental Gloabals

Post by KiwiHawk »

This has been fixed. Thread can be moved to implemented?
Dev for Bob's mods, Angel's mods, Helmod, Sea Block, Circuit Processing, Science Cost Tweaker.

Buy me a coffee

Post Reply

Return to “Implemented mod requests”