lua-users home
lua-l archive

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

On Feb 2, 2010, at 3: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.

If one could deal with introducing a new keyword:

	local x, y, z from t

That actually is more descriptive, but it comes at the cost of a new keyword.

I'm imagining it becoming much more common to write things like:

	local math, string from _G

Without the keyword cost, one could try:

	in t local x, y, z

But that doesn't look as pretty.

This is so tempting to go add. The only problem (other than 5.2 using "in") is that while I experiment with patches (e.g., I've done the work to support obj:[ method ]( ... ) to simplify calling methods via expressions), I'm really cautious about putting them into practice for anything large because they make it harder to move forward with new Lua releases or switch to LuaJIT.