lua-users home
lua-l archive

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

On Fri, Jun 11, 2010 at 9:37 PM, Tomas Lundell <> wrote:
> For Lua 6, if we had some sort of macro facility then that would cover these
> cases much more nicely:
> import => [macro expansion] =>
> local world = import("")

What happens then if you want to import both "" and ""?

I'm fine with `local world = import ""`.  As seen, the
package names can often be longer than the symbols we want to import
into the local namespace, and we may even want the flexibility in
renaming the local symbols (`local Earth = import
"hello.PlanetEarth"`).  Having the explicit `local` also clearly
identifies the names of all locals in our file (with a couple special
cases like `for x`, `self`, and `_ENV`).  This is important for
program analysis since locals shadow globals.

What some have requested is a compile time expansion `local a,b,c in
some_table_expression` --> `local _t =  some_table_expression; local
a,b,c = _t.a, _t.b, _t.c`, which is implemented in the "Unpack Tables
by Name" patch [1].  The table could be any arbitrary table, including
a module: `local getlocal,getupvalue in require "debug"`.