|
Am 11.04.2013 19:51 schröbte Petite Abeille:
On Apr 11, 2013, at 2:50 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:Anyway, can't you hanlde all them the same way, by packing each module inside a function, more or less like this? do -- module A "inlined" here local _ENV = _ENV local function mod (...) <<module original source code>> end package.preload.A = mod endWow… the delicious irony… this just look exactly like all my 5.2 module code:
That's odd, since it serves a different purpose. The first piece of code is a way to collect multiple modules into a single file no matter how those modules are implemented, while your 5.2 module code is a specific way to implement modules that are tables.
do --8<-- local _ENV = module( 'IMAP' ) -- stuff goes here... end -->8-- [...] How caustic that we now all have to find new, wonderful, and half-baked ways to re-invent 5.1 module functionalities… progress it is not.
Actually, the code above is necessary to support all those "half-baked ways to re-invent 5.1 module functionalities" -- yours, which sets _ENV directly, and the official LUA_COMPAT_MODULE function, which modifies a chunk's first upvalue.
Philipp