lua闭包
function MakeCounter() local t = 0 return function() t = t + 1 return t end end local func = MakeCounter() for i = 0,10 do print(func()) end local func2 = MakeCounter() for i = 0,10 do print(func2()) end
>lua -e "io.stdout:setvbuf 'no'" "main.lua"
1
2
3
4
5
6
7
8
9
10
11
1
2
3
4
5
6
7
8
9
10
11
>Exit code: 0
本博客注有“转”字样的为转载文章,其余为本人原创文章,转载请务必注明出处或保存此段。c++/lua/windows逆向交流群:69148232