function stateChanger()
local n = 9
function inc()
n = n + 1; return n
end
function dec()
n = n - 1; return n
end
return inc, dec
end
local add, sub = stateChanger()
print(add()) -- 10
print(add()) -- 11
print(add()) -- 12
print(sub()) -- 11
print(sub()) -- 10
print(add()) -- 11
print(add()) -- 12
print(sub()) -- 11
Sunday, May 13, 2012
Lua의 closure에서 두개 이상의 함수를 리턴하는 예
Labels:
Lua
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment