lua-users home
lua-l archive

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


On Tue, Oct 27, 2020 at 11:38 PM Andrew Gierth
<andrew@tao11.riddles.org.uk> wrote:
>
> >>>>> "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.

Speaking of my example, it answered the two questions above, not just
the second one. PiL 3 recommends that tables are the general way to
handle variadic arguments. There was a discussion and some
benchmarking here four-five years ago, when it was found that one
should worry about the impact of table creation only when the actual
number of variadic arguments is 0, 1 or 2. With progressively more
variadic arguments, they are first on par and then (vastly) better
than other ways of handling variadic arguments.

It is true that in the answer to the second question tables are
redundant, but more generally they are the way to go.

For example, I do not think there is a straight-forward way to pass
all but the last return value, or more generally any that is not an
N-th return value, or pass no more than first N return values, even if
N is statically fixed. With tables this is trivial and performs well,
for N both static and dynamic.

Cheers,
V.