Getting a function name?

I was wandering if there is a way to get the name of a function?
Example:
[lua]
function randomFunction(a, b)
return a+b;
end

local functionName = getfunctionName(randomFunction);
MsgN(functionName);
[/lua]
Would output:



randomFunction


If that makes any sense.

As a string or as a function reference?

using debug.getinfo, you’ll notice that you cannot. Someone has explained it better here.

[lua]PrintTable( debug.getinfo( _G[“PrintTable”] ) )[/lua]

outputs


nups	=	0
what	=	Lua
func	=	function: 0353CC60
lastlinedefined	=	54
source	=	@lua\includes\util.lua
currentline	=	-1
namewhat	=	
linedefined	=	30
short_src	=	lua\includes\util.lua

more debug.getinfo

not really sure why you would want to anyway.

As a string.

Don’t really understand the purpose of why you would want the name of the function, if you would explain we might be able to help you better.

Just for benchmarking or debugging so i could output something like


functionName ran 1000000 times in 0.4322341

or something like that. Not really necessary but i figured i might as well ask.

You could open the file returned by debug.getinfo, read the line and parse it with a pattern to get the name, but that might not always work.

If it’s a global function there’s also the option of looking through _G for an entry whose value corresponds to the address pointed to by debug.getinfo, and then just grabbing the key.