lua-users home
lua-l archive

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

On Sat, Jan 9, 2010 at 6:29 AM, steve donovan wrote:
> However, (and this is a nasty) there are some tricks you cannot do
> with debug.setfenv.
> Consider this implementation of David Manura's 'module environment ~=
> module table' idea:  [package.clean] ....

>    debug.setfenv(3,env)  .....
> ../lua: ./closed.lua:12: 'setfenv' cannot change environment of given object

In 5.1, setfenv can take a stack level number but debug.setfenv can
not.  debug.setfenv can take a userdata but setfenv could not.  One is
not a subset of the other.  Now, in 5.1 you can alternately obtain the
function at a given stack level number like debug.getinfo(3, 'f').func
and then call setfenv or debug.setenv on it to achieve the same effect
to setenv with a stack level number.  In Lua 5.2.0-work1, this
functionality is maintained, though in the debug library.