lua-users home
lua-l archive

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

Hi Miles,

On Sat, Jan 9, 2010 at 7:11 AM, Miles Bader <> 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
> debugging.

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
> code.

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.

-Patrick Donnelly

"Let all men know thee, but no man know thee thoroughly: Men freely
ford that see the shallows."

- Benjamin Franklin