[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table:method as an expression (I know I know, just hear me out, okay? :D)
- From: v <v19930312@...>
- Date: Sun, 22 Mar 2020 13:10:02 +0300
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>