lua-users home
lua-l archive

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


Greetings lua-l!

While considering how to do a few things in Lua for a future project I have in mind I got a bit distracted thinking about Lua upvalues and ended up at the following thought:

The last argument to `load` is passed as the first upvalue to the new closure that is returned. This is usually the environment (at least for what the manual refers to as "main chunks"), which is what this argument is supposedly meant for.

If, however, you dump any function as bytecode and load it again, its environment may be the second, third or fifth upvalue, or it may not have an environment at all (a function that accesses no globals).

So my question is, why make the first upvaue a special case in the first place? This seems very un-Lua to me. A more generic (and backwards-compatible) alternative would be for all additional arguments to load to be passed as upvalues to the new closure in order of appearance.

    load(chunk [, chunkname [, mode [, ...]]])

The code to set the n-th upvalue obviously already exists and gets called by the load function, so, I expect, to someone who's familiar with Luas C implementation this change should be trivial (At least one could assume so).

Of course, my reason for opsting this here is because I'd like to hear what others think, so please, *do* give your opinions :)