do
local test = false
do
local bdfbdfb
bdfbdfb = function()
local b = "test"
local _1, _2 = debug.getlocal(2, 2)
print(_1, _2)
print(test)
end
return bdfbdfb()
end
end
Почему не выводит значение переменной
test ?
function locals()
local variables = {}
local idx = 1
while true do
local ln, lv = debug.getlocal(2, idx)
if ln ~= nil then
variables[ln] = lv
else
break
end
idx = 1 + idx
end
return variables
end
function upvalues()
local variables = {}
local idx = 1
local func = debug.getinfo(2, "f").func
while true do
local ln, lv = debug.getupvalue(func, idx)
if ln ~= nil then
variables[ln] = lv
else
break
end
idx = 1 + idx
end
return variables
end
do
local a = 2; for x, v in pairs(locals()) do print(x, v) end
end
local a= 2;
local f = function()
local b = a;
for x,v in pairs(upvalues()) do
print(x,v)
end
for x, v in pairs(locals()) do print(x, v) end
end; f()
do
local test = false
do
local bdfbdfb = nil
bdfbdfb = function()
local b = "test"
for x, v in pairs(locals()) do print(x, v) end
for x,v in pairs(upvalues()) do
print(x,v)
end
end
--for x, v in pairs(locals()) do print(x, v) end
return bdfbdfb()
end
end
не все локальные переменные выводит, почему?