lua-users home
lua-l archive

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


2011/6/20 Xavier Wang <weasley.wx@gmail.com>:
> local ok, rets... = pcall(func)
> pcall(cleanup())
> if not ok then
>     pcall(err_func)
>     error(rets...)
> end
> -- using rets, note that before here I don't actually know how many values
> the function returns
> local a,b,c = rets...

When an error occurs, there will be precisely one return value after
ok, so you can do:

local ok, a, b, c = pcall(func)
pcall(cleanup)
if not ok then
  pcall(err_func)
  error(a)
end
-- use a,b, c