lua-users home
lua-l archive

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


On Sun, 2020-03-22 at 10:55 +0100, DarkWiiPlayer wrote:
> I noticed the other day that I surprisingly often find myself writing
> code like this:
> 
>     function_with_callback(stack.pop, stack, some, other, arguments)
> 
> As I was once again writing the same snippet of code, I had the
> following idea:
> 
> What if I could just write
> 
>     function_with_callback(stack:pop, some, other, arguments)

This one have a problem in that if not last argument returns few
results only first one is passed to function. For example:

print(table.unpack{1,2,3}) --> 1 2 3
print(table.unpack{1,2},3) --> 1 3   (that's the problem)
print(1,table.unpack{2,3}) --> 1 2 3 (but last arg expands properly)

So you can't just implement what you suggest as an operator returning
two results to make this case work, making it rather complex. That
said, this feature would be very useful with pcall.
-- 
v <v19930312@gmail.com>