[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: getting function name
- From: jseb <gmane2013@...>
- Date: Sun, 16 Nov 2014 20:19:06 +0100
> Take a look at package.loaded. Not only does it contain a
> reference to package, but it also contains a reference to _G.
Ah yes, just saw that.
And there were problem also in the searching loop: when found, the
search continues and it ends with returning nil. Each returning
call should test if there were some success previously.
Correct version:
function _get_fx_name(fx, t)
local ret = nil
for k,v in pairs(t) do
if fx == v then
print("found", k,v)
return k
end
if type(v) == "table" and k ~= "_G" and k ~= "package" then
ret = _get_fx_name(fx, v)
if ret then goto exit end
end
end
::exit::
return ret
end
function get_fx_name(fx)
local name
name = _get_fx_name(fx, _ENV)
name = name or "unknown function"
return name
end
I know it's pretty not pretty, but that's the most i can do.