我有以下的函数。
function test()
local function test2()
print(a)
end
local a = 1
test2()
end
test()
这会打印出nil
以下脚本
local a = 1
function test()
local function test2()
print(a)
end
test2()
end
test()
输出结果为1。
我不理解这个。我认为声明一个本地变量使它在整个块中有效。由于变量'a'在test()函数作用域中声明,而test2()函数也在同一作用域中声明,为什么test2()没有访问test()本地变量的权限?