lua-users home
lua-l archive

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


I think that this deserves a new thread.
This message is an answer to:

  http://article.gmane.org/gmane.comp.lang.lua.general/84127 (Roberto)
  http://article.gmane.org/gmane.comp.lang.lua.general/84128 (Petite Abeille)
  http://article.gmane.org/gmane.comp.lang.lua.general/84129 (Matthew Wild)

So:  in Lua 5.1 one can do this,

  module("mod1")
  ...
  module("mod2")
  ...

while in Lua 5.2 one has to do this,

  do local _ENV = mymodule("mod1")
     ...
  end
  do local _ENV = mymodule("mod2")
     ...
  end

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-(

  Cheers,
    Eduardo Ochs
    eduardoochs@gmail.com
    http://angg.twu.net/
    http://angg.twu.net/eev-puro/mini-lua-intro.e.html