lua-users home
lua-l archive

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


I'm not even sure if this would be possible?

local variables are assigned to stack slots at compile time, so something like this would require the compiler to know the contents of a table at compile-time, not run-time, to determine the set of locals to create. Since tables are dynamic, this means the compiler would have to know, in advance, what the contents of a table was going to be at run time. Does not compute.

The only thing I think would work is a bit of syntactic sugar. Something like:

local a, b, c from some_table

Which the compiler could re-write as:

local a, b, c = some_table.a, some_table.b, some_table.c

This is robust at both compile and run-time given Luas handling of undefined table items, but doesn't give you the "wildcard" you were suggesting.

--Tim



On May 18, 2013, at 1:06 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:

> Often on this list voices have gone up proposing a language addition
> that would allow one to automate the following process:
> 
>    local concat,insert,remove,pack,sort,unpack=
>       table.concat, table.insert, table.remove, table.pack,
>       table.sort, table.unpack
> 
> by saying Pythonically
> 
>    from table import *
> 
> or whatever.  Has anybody ever actually produced a kernel patch that
> implements something of the kind?
>