lua-users home
lua-l archive

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

On Tue, Feb 2, 2010 at 11:08 PM, Gavin Wraith <> wrote:
> I have always found Peter Shook's "Unpack Tables by Name" patch
> very convenient with Lua 5.1. You could simply write
>  local x,y,z in t
> in place of
>   local x,y,z = t.x,t.y,t.z
> In Lua 5.2 the syntax of Shook's patch would appear to clash
> with that for lexical environments, because after "local x,y,z in t"
> the keyword "do" is expected. Does anybody have any suggestions
> for a resolving this clash. Shook's patch is for reading values
> from a table without having to keep repeating the table expression,
> whereas lexical environments are for writing to a table without
> having to keep repeating the table expression. It would be more
> be more balanced if both could be done.

One obvious solution is to change the token which the patch expects
between the name list and the expression. Personally, I think that "x,
y, z from t" reads better than "x, y, z in t", and whilst Lua does not
have a "from" keyword, the arrow-like "<=" could be used instead:
local x, y, z <= t
in place of
local x, y, z = t.x, t.y, t.z