lua-users home
lua-l archive

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


> What are the expected use cases for in env do ... end? As I'm
> understanding it, it basically just saves writing env.name for various
> reads and writes at the expense of losing access to other globals
> unless they are provided by env. So, it could be implemented as:
> 
> 	do
> 		local _env = env
> 		... code with global accesses modified to reference _env ...
> 	end
> 
> Is this a correct understanding? 

Yes. This is exactly what the compiler does.


> That would seem to make sense as a syntactic replacement for some of the
> setfenv tricks but those tricks seem like tricks much of the time as
> opposed to particularly clean ways to write things. See the discussions
> about issues with the module function and package.seeall, for example.

Well, I particularly live well with 'module' (e.g., the package 're'
from LPEG uses it without the seeall option). It is far from perfect,
but it seems a good balance.

-- Roberto