i did something like this to achieve privacy:
Code: Select all
function initGlobals()
global = {}
local internals={}
internals.nextId = 0
global.getNextId = function()
internals.nextId = internals.nextId+1
return internals.nextId-1
end
end
so i use this:
Code: Select all
function initGlobals()
global = {}
global.__internals={}
global.__internals.nextId = 0
global.getNextId = function()
global.__internals.nextId = global.__internals.nextId+1
return global.__internals.nextId-1
end
end
this experience makes me think, that i better stay away from closures alltogether when modding for factorio. or at least always make sure very carefully, that the internals are stored somewhere in 'global'. anyone with experiences on that topic?