[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Suggestion for 5.3: import() for creating a "slew" of locals
- From: Alexander Gladysh <agladysh@...>
- Date: Mon, 18 Nov 2013 22:57:04 +0400
On Mon, Nov 18, 2013 at 6:20 PM, Pierre-Yves Gérardy <pygy79@gmail.com> wrote:
>> Is syntactic sugar for:
>> local t = some_table_expression
>> local a, b, c = t.a, t.b, t.c
>
> That's almost exactly what I do, sans sugar.
>
> local s, t = string, table
> local s_byte, s_sub, t_concat, t_insert, t_remove, t_unpack
> = s.byte, s.sub, t.concat, t.insert, t.remove, t.unpack
>
> I type them using the multiple cursor option in my editor, then change
> the underscores to dots.
>
> The alignment (hopefully your mail client uses a fixed width font)
> makes it easier to spot errors.
>
> You must like prefixes, though.
FWIW, what we do, regarding import, is
local foo, bar = import 'baz.lua' { 'foo', 'bar' }
local insert, concat = import (table) { 'insert', 'concat' }
would work too (but we usually don't do that, favoring prefixed version).
My 2c,
Alexander.
P.S. Implementation (not the most elegant) is here:
https://github.com/lua-nucleo/lua-nucleo/blob/master/lua-nucleo/import.lua