[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Deprecating setfenv()
- From: Patrick Donnelly <batrick@...>
- Date: Sat, 9 Jan 2010 18:22:19 -0700
On Sat, Jan 9, 2010 at 7:11 AM, Miles Bader <firstname.lastname@example.org> wrote:
> No. That's not what the debug package signifies.
> A constant refrain in the Lua community is that you should _never_
> depend on "debug" package functions, and should only use them for
I don't think that's quite what we all think. The debug library not
only holds debugging facilities but functions that provide access to
"protected" functionality. In my serialization library (all Lua), I
*have* to have access to debug.getupvalue, debug.setupvalue, etc.
>> Besides, the new syntax is a lot more readable in my opinion and leads
>> to code that is easier to maintain.
> setfenv/getfenv are _not_ user-level functions; they're functions used
> by people writing frameworks for users to use. So you're right, they're
> low-level, but they're _useful_ for people that are writing low-level
So are the other debug functions I mentioned above. But in the same
way debug.upvalue violates Lua's guarantee that the upvalue is
"protected", so does setfenv/getfenv for function environments (of
course this guarantee hasn't been made before). I was apprehensive at
first, but I think this is the right way to go forward. Lexical
environments capture most of the use cases of setfenv. We have loadin
for dynamic code. If your code is not dynamic (like the closure
example in the OP), then you can use lexical environments just fine.
"Let all men know thee, but no man know thee thoroughly: Men freely
ford that see the shallows."
- Benjamin Franklin