lua-users home
lua-l archive

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


>>>>> "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.