Function 如何获取函数名

Function 如何获取函数名,function,lua,Function,Lua,我有个问题。如何在不使用调试命名空间的情况下知道调用我的函数的函数名。例如: function test1() test2() end function test2() --How to get here name of function which have called my function test2. --How to get here "test1"? end 如果允许我使用调试名称空间,这将很容易,但我可以使用。有人知道吗? 对不起,我的英语不好。函数没有名称

我有个问题。如何在不使用调试命名空间的情况下知道调用我的函数的函数名。例如:

function test1()
   test2()
end

function test2()
   --How to get here name of function which have called my function test2.
   --How to get here "test1"?
end
如果允许我使用调试名称空间,这将很容易,但我可以使用。有人知道吗?
对不起,我的英语不好。

函数没有名称。函数是Lua中的值,就像数字
5.23
,或者字符串
“string”
。这些都是值,它们可以存储在许多地方。因此,函数没有实名。调试系统根据函数最初的声明方式分配函数名,仅此而已


如果一个函数需要知道是谁调用了它,那么该函数有责任将调用方作为函数参数。

这并不能解决一半的问题,但您可以为函数命名。我不知道你是否能用这个来解决你的问题

-- create a functable --

functable = {name = "bob"}
metatable = {}

metatable.__call = function()
    print "you just called a table!"
end

setmetatable(functable,metatable)

-- call a functable and get it's name --

functable()
print(functable.name)

这个想法很有趣,但是有很多函数调用test2()。我找到了大约50个文件,每个文件有2-5个调用。这要花很多时间才能完成change@user1274868:嗯,你有两个选择:要么改变所有这些电话,要么不打。你想要的是不可能的。没有调试库也不行,即使这样,也只有一些函数有名称。好的,谢谢你的回答。我将创建一个脚本<,它将在调用test2(“module_name”)时替换函数test2()的所有调用