[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Simulating getfenv for Lua 5.2
- From: David Manura <dm.lua@...>
- Date: Sat, 12 Jun 2010 21:47:14 -0400
On Fri, Jun 11, 2010 at 9:37 PM, Tomas Lundell <email@example.com> wrote:
> For Lua 6, if we had some sort of macro facility then that would cover these
> cases much more nicely:
> import hello.world => [macro expansion] =>
> local world = import("hello.world")
What happens then if you want to import both "hello.world" and "goodbye.world"?
I'm fine with `local world = import "hello.world"`. 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 . The table could be any arbitrary table, including
a module: `local getlocal,getupvalue in require "debug"`.