Re: Returning nil vs returning nothing
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Returning nil vs returning nothing
- From: Viacheslav Usov <via.usov@...>
- Date: 2020年10月27日 20:45:22 +0100
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.