lua-users home
lua-l archive

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


> 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.

Lexical environments can be used for reading as well. The code below
does the equivalent of "local x,y,z in t":

in t do
	local x,y,z = x,y,z
	...
end

There's still a repetition but it's like that already in 5.1.