Wednesday, 28 August 2013

Why is 'name' nil for getinfo(1)

Why is 'name' nil for getinfo(1)

I'm trying to put together a lua testing framework that lets you know the
function that had the problem, but when I switched from loadstring to _G,
(I switched so my test harness could see the results of the function call)
my functions started using 'nil' for the function name
Why can _G not detect the name of the current function in the following code?
function blah()
print(debug.getinfo(1).name)
end
local name = 'blah'
local status, result = pcall(_G[name]) -- Outputs 'nil'
local status, result = pcall(loadstring(name..'()')) -- Outputs 'blah'

No comments:

Post a Comment