lua-users home
lua-l archive

Inspecting argument names

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I'm trying to find a way to get the argument names via the debug
interface, but falling flat on my face.
==> they aren't available from debug.getinfo
The best idea I've got at the moment is to set a call hook and then
inspect with debug.getlocal; but I can't bail out of the function from
a hook:
 local names
 local function hook ()
 debug.sethook() --Turn off hook.
 names = {}
 local i=1
 while true do
 local name , value = debug.getlocal(2,i)
 if name == nil or name:sub(1,1) == "(" then break end
 names[i]=name
 i=i+1
 --print(name,value)
 end
 end
 local function getargnames ( func )
 debug.sethook(hook,"c")
 func()
 return names
 end
 local argnames = getargnames(function(a,b,c) print("Don't do the
function") end)
If I try to throw an error from the hook; I can't seem to catch it
with a pcall. Also pcall seems to make the argument list disappear.
(replace func() above with pcall(func))
Anyone got any ideas?
Failing any good ideas; could the lua authors include this in the
debug info somewhere?
Regards,
Daurn.

AltStyle によって変換されたページ (->オリジナル) /