> Or is there a function in Lua I could “wrap” for this kind of tracing?
function WRAP(f)
return function (...)
print("WRAP in ",...)
local t=table.pack(f(...))
print("WRAP out",table.unpack(t))
return table.unpack(t)
end
end
I would suggest passing the size of the table captured by table.pack explicitly to table.unpack, that way the function being wrapped can return 'nil' as the last return value without it being dropped. The table may have multiple borders.
function WRAP(f)
return function (...)
print(">>", ...)
local res = table.pack(f(...))
print("<<", table.unpack(res, 1, res.n))
return table.unpack(res, 1, res.n)
end
end