Yes, for Lua functions, but not for C functions. This is a bit painful and a bit sketchy.
debug.getlocal works on called functions, so you need to call this function. It does not display any hints of ... unless the call has enough parameters. The code below tries 20 parameters.
debug.sethook with a call event allows you to intercept a function before running any code.
This algorithm works with Lua 5.2. Old versions would be similar, but not the same:
assert(_VERSION=="Lua 5.2", "Must be compatible with Lua 5.2")
Small helper iterator (can be built in to increase efficiency):
local function getlocals(l) local i = 0 local direction = 1 return function () i = i + direction local k,v = debug.getlocal(l,i) if (direction == 1 and (k == nil or k.sub(k,1,1) == '(')) then i = -1 direction = -1 k,v = debug.getlocal(l,i) end return k,v end end
Returns a signature (but can return a parameter counter and uses Varargs instead):
local function dumpsig(f) assert(type(f) == 'function', "bad argument #1 to 'dumpsig' (function expected)") local p = {} pcall (function() local oldhook local hook = function(event, line) for k,v in getlocals(3) do if k == "(*vararg)" then table.insert(p,"...") break end table.insert(p,k) end debug.sethook(oldhook) error('aborting the call') end oldhook = debug.sethook(hook, "c") -- To test for vararg must pass a least one vararg parameter f(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) end) return "function("..table.concat(p,",")..")" end