lua-users home
lua-l archive

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


On Tue, Oct 27, 2020 at 8:26 PM Grzegorz Krasoń
<grzegorz.krason@gmail.com> wrote:

> How to recognize this at the function call? For example how to implement an universal wrapper that would suppress all errors and still returns exactly the same thing as wrapped function in case of success?

function ret(...)
    local n = select('#', ...)
    local t = table.pack(...)
    return table.unpack(t, 2, n)
end

function supperess(f, ...)
    return ret(pcall(f, ...))
end

print(supperess(f)) -- prints nil
print(supperess(g)) -- prints empty line

Cheers,
V.