lua-users home
lua-l archive

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


On Sun, Nov 17, 2013 at 4:03 AM, Paige DePol <lual@serfnet.org> wrote:
Rena, you should check out the "Unpack Tables by Name" patch over on the Power Patches page (http://lua-users.org/wiki/LuaPowerPatches)

I have not patched my Lua with this patch yet, however, it looks like it would do exactly what you desire; namely let you assign locals to the result of table key lookups in a concise manner!

>From the Power Patches page:

Enhancement to the assignment statement to unpack named values from tables using the in keyword:
    local a, b, c in some_table_expression

Is syntactic sugar for:
    local t = some_table_expression
    local a, b, c = t.a, t.b, t.c

~pmd~



On Nov 17, 2013, at 2:37 AM, Rena <hyperhacker@gmail.com> wrote:

> But the point to understand is that this must be a purely _static_
> operation at compile time. So implementing something like 'using
> table.*' hits the problem of determining the contents of 'table' at
> compile time.  So it would have to be an explicit list of entries to
> localize, and understood as syntactical sugar for all those pesky
> 'local insert = table.insert' statements.



That's an interesting patch, and I've dabbled in patched Lua before, but I like to stick with unmodified versions when I can. Maybe the fact that it's already been implemented can help push for it to be added to an official version...

--
Sent from my Game Boy.