lua-users home
lua-l archive

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


Hi everyone,

From what I've seen so far I like most of the changes in Lua 5.2.0 but there's one thing I cannot wrap my mind around. It looks like getfenv() and setfenv() are being moved to the debug library (in other words deprecated) while the supposed replacement really isn't...

Several of the modules I've written use setfenv() and though each of those modules contains just a single call to setfenv() the functionality of the whole module depends on that setfenv() call. Apart from that, if my understanding is correct then the supposed replacement is really just a simple syntactical wrapper for the following functionality:

local scope = {}
setfenv(function()
	foo = 1
	bar = 2
end, scope)()
assert(foo == nil)
assert(bar == nil)
assert(scope.foo == 1)
assert(scope.bar == 2)

This is obviously already possible in Lua 5.1, but more importantly it is one very narrow use-case of setfenv(). I've grown to appreciate setfenv() as core Lua functionality and now it is being deprecated without a replacement...

Finally I'm getting to my point: I'm wondering what made the Lua authors decide to remove setfenv() and replace it with a very narrow subset of its functionality?! Of course I'm hoping that I misunderstood the replacement or can change the Lua authors' minds about it, but if neither of those is an option than I'll settle for a clear understanding of the decision making process :-)

 - Peter Odding