Content deleted Content added
Jackmcbarn (talk | contribs) different method of breaking isolation |
Jackmcbarn (talk | contribs) thoughts about making duplicate upvalues |
||
Line 1:
local p = {}
local function makeCounter()
local counter = 0
return function()
counter = counter + 1
return counter
end
end
function p.main(frame)
local myCounter = makeCounter()
myCounter()
myCounter()
myCounter()
myCounter()
myCounter() -- this returns 5
local newCounter = myCounter
newCounter() -- this returns 6
return myCounter() -- this returns 7, since newCounter and myCounter are really the same thing. is there any way to make a copy of a function that doesn't share upvalues?
end
|