lua-users home
lua-l archive

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


> So, if Lua were to apply neither `_G` nor the environment of the
> caller, what would it apply?  I think a reasonable design is for
> `load` and its variants to default the environment to `nil` unless an
> environment is explicitly given as an argument.  One such argument is
> the current lexical environment (`_ENV`), which in the current Lua 5.2
> proposal must be explicitly given.  The Lua-5.2.0-work2 `loadin`
> function roughly follows that design, but the other functions like
> `loadfile` still apply `_G`, limiting their reuse.

Consider that 'loadin' is the "real" function. You can do whatever you
want with it.

load and loadfile are auxiliary functions for the special case when
someone wants to load a chunk in the standard global environment. I may
be wrong, but I guess the vast majority of cases wants exactly that, so
it makes sense to have those special functions. There is a compatibility
problem too: loadfile is *much* more used then setfenv, so it would be
a shame to break it.

-- Roberto