摘自 https://www.cnblogs.com/elvisxu/archive/2011/07/19/2110063.html
xxx = 100
function func()
local index = 0
xxx = xxx + 1
print("Hello")
return function()
print(index)
index = index + 1
end
end
local inner = func() --调用func()函数,返回内部函数给inner,打印结果:"Hello"
print(xxx)
print(inner) --打印结果:function:0037BE88
print(xxx)
inner() --调用内部函数,打印结果:0
print(xxx)
inner() --调用内部函数,打印结果:1
print(xxx)
print("=================")
local other = func() --获取另一个内部函数实例,打印结果:"Hello"
print(xxx)
other() --调用另一个内部函数实例,打印结果:0
print(xxx)
other() --同上,打印结果:1
print(xxx)
Hello
101
function: 00fdb670
101
0
101
1
101
=================
Hello
102
0
102
1
102
来源:CSDN
作者:klm123698745
链接:https://blog.csdn.net/klm123698745/article/details/104127434