In Lua, how can you print the name of the current function, like the C99 __func__ identifier?

前端 未结 7 1767
别那么骄傲
别那么骄傲 2021-02-13 03:49

Something like this:

function foo()
    print( __func__ )
   ...
end

How can it be done?

7条回答
  •  -上瘾入骨i
    2021-02-13 04:16

    #!/usr/bin/lua
    
    local function myFunc()
     print(debug.getinfo(1, "n").name);
    end
    myFunc()
    

提交回复
热议问题