[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: modules, require, magic
- From: Eduardo Ochs <eduardoochs@...>
- Date: Sun, 16 Oct 2011 19:39:58 -0200
I think that this deserves a new thread.
This message is an answer to:
So: in Lua 5.1 one can do this,
while in Lua 5.2 one has to do this,
do local _ENV = mymodule("mod1")
do local _ENV = mymodule("mod2")
where "mymodule" is a more or less trivial function, that can be
implemented in pure Lua.
In my opinion the two worst functions in Lua 5.1 are "require" and
"module". They contain too much magic, and - in my opinion again -
their implementation details are somewhat arbitrary. My suggestion
about the best way to cope with that is certainly going to be totally
different from Petite Abeille's... here it is: add to the "etc/"
directory of Lua 5.2 implementations of "require" and "mymodule" in
pure Lua, blessed by the Lua team, and equivalent to their
implementations in C. People who don't understand their behavior very
well ("idiots like me") will then be able to clarify things by just
adding "print"s and running tests.
By the way, how hard it would be implement something like the "module"
in the top chunk above in Lua 5.2? What are the difficulties? Would it
need to call the debug library? Would it need to do something that can
only be done from C? This is a honest, though maybe a dumb, question...
I am not a programmer - I am just a mathematician / logician /
category theorist - and I DID try to understand modules at one point,
but things didn't make enough sense to me, so I gave up and lived
happily ever after... 8-(
- Re: modules, require, magic, Patrick Mc(avery
- Re: modules, require, magic, Petite Abeille
- Re: modules, require, magic, Roberto Ierusalimschy
- Re: modules, require, magic, Javier Guerra Giraldez