[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Returning nil vs returning nothing
- From: Andrew Gierth <andrew@...>
- Date: Tue, 27 Oct 2020 22:37:44 +0000
>>>>> "Grzegorz" == Grzegorz Krasoń <grzegorz.krason@gmail.com> writes:
Grzegorz> How to recognize this at the function call? For example how
Grzegorz> to implement an universal wrapper that would suppress all
Grzegorz> errors and still returns exactly the same thing as wrapped
Grzegorz> function in case of success?
The examples that use pack/unpack seem misguided since they're
allocating a table unnecessarily.
Instead, how about:
function suppress(func, ...)
local function drop1(success, ...)
if success then
return ...
else
return
end
end
return drop1(pcall(func, ...))
end
--
Andrew.