How to get function call inside function in lua?

How can I get the calling function inside a function in lua?

In particular, I am looking for (for debugging purposes in the output of a command, for example, print) the possibility of registering when calling a general function indicating where it was called from.

It can only be the name of the file from which it was called, for example,

i.e.

File 1 - Has commonly used function 

File 2 - Calls of the the file one functions

PS Dirt - I actually get zero at the same time - is this normal? It is not possible to get more information in this case:

The called file;

SceneBase = {}
  function SceneBase:new(options)
  end
return SceneBase

The calling file:

require("views.scenes.scene_base")
local scene = SceneBase.new()
+3
source share
2 answers

debug.getinfo(2).name , , . , nil, - , , ?.

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'
+5

Lua .

0

All Articles