lua-users home
lua-l archive

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


> On Wed, Jun 9, 2010 at 11:10 AM, Roberto Ierusalimschy
> <roberto@inf.puc-rio.br> wrote:
> > If 'import' is only called from the main function in a module, then you
> > can safely assume that the environment will be the first upvalue of the
> > callee function. So, you can use debug.getupvalue to get its value:
> 
> [...]
> 
> >From a standpoint of engineering and larger scale programming, I
> really don't like stuff like this in Lua that often works but breaks
> in weird cases or transformations [2].  So, I don't recommend
> debug.getupvalue(debug.getinfo(2).func, 1) but rather something
> explicit like _ENV:import "hello.world" mentioned by Patrick.

I would like to make it clear that I am not proposing getupvalue as a
regular practice, only as a way to achieve some level of compatibility
in a program when you want to change it as little as possible.

-- Roberto