Home
Random
Nearby
Log in
Settings
Donate Now
If Wikipedia is useful to you, please give today.
About Wikipedia
Disclaimers
Search
Module:Sandbox/Jackmcbarn: Difference between revisions
Module
Talk
Language
Watch
View history
Edit
Browse history interactively
← Previous edit
Next edit →
Content deleted
Content added
Revision as of 18:38, 13 May 2014
edit
Jackmcbarn
(
talk
|
contribs
)
31,380
edits
thoughts about making duplicate upvalues
← Previous edit
Revision as of 17:40, 23 May 2014
edit
undo
Jackmcbarn
(
talk
|
contribs
)
31,380
edits
test isolation break
Next edit →
Line 1:
local p = {}
local function makeCounter()
local counter = 0
return function()
counter = counter + 1
return counter
end
end
function p.main(frame)
return mw.loadData('Module:Sandbox/Jackmcbarn/data')[1]
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