Skip to content
Snippets Groups Projects

Table print improvements

Merged Petr Špaček requested to merge table_print_2 into master
1 file
+ 13
18
Compare changes
  • Side-by-side
  • Inline
+ 13
18
@@ -377,28 +377,23 @@ local function funcsign(f)
local function hook()
delay = delay - 1
if delay == 0 then -- call this only for the introspected function
for i = 1, math.huge do
-- stack depth 2 is the introspected function
-- stack depth 2 is the introspected function
local debuginfo = debug.getinfo(2)
for i = 1, debuginfo.nparams do
local k = debug.getlocal(2, i)
if (k or '('):sub(1, 1) == '(' then
break -- internal variable, skip
else
table.insert(func_args, k)
end
table.insert(func_args, k)
end
if debug.getlocal(2, -1) then
-- vararg function
table.insert(func_args, "...")
if debuginfo.what == 'C' then -- names N/A
table.insert(func_args, '?')
elseif debuginfo.isvararg then
table.insert(func_args, "...")
end
debug.sethook(oldhook)
error('aborting the call to introspected function')
end
debug.sethook(oldhook)
error('aborting the call to introspected function')
end
end
oldhook = debug.sethook(hook, "c") -- invoke hook() on function call
-- fake arguments, necessary to detect vararg functions
local fakearg = {}
for _ = 1, 64 do fakearg[#fakearg + 1] = true end
f(unpack(fakearg)) -- huh?
oldhook = debug.sethook(hook, "c") -- invoke hook() on function call
f(unpack({})) -- huh?
end)
return "(" .. table.concat(func_args, ", ") .. ")"
end
Loading