how to get caller of function within a function in lua?
snippet in lua

how to get caller of function within a function in lua?

user2785

function foo() print(debug.getinfo(2).name) end

-- _G["foo"] => function name is a string
function bar() foo() end
bar() --> 'bar'

-- _G[123] => function name is a number
_G[123] = function() foo() end
_G[123]() --> '?'

-- function has no name
(function() foo() end)()  --> 'nil'