lua-users home
lua-l archive

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


"Patrick Mc(avery" <patrick@spellingbeewinnars.org> writes:
> Actually I don't want to change Lua per say, it's just that with all the
> module discussion I feel that a large part of the list is arguing for
> the wrong sort of things. I think that there should be more attention
> paid to making it simpler to use.

I dunno, the new "purer" modules in 5.2 actually seem crazy easy to
use, and also easy to understand if described reasonably:

``A "module" in Lua is just a table containing some functions.

To load a module, you use the "require" function, which takes a name,
finds the corresponding source file, and returns whatever that source
file returns -- which is usually the table containing that module's
functions.

So:

   * To _use_ a module, just call the "require" function to find it,
     store the table it returns in a variable, and call the functions
     in that table as you wish:

      local M = require "M"
      ...
         M.oink ();
         M.barf ();
      ...

   * To _define_ a module, just make your source file return a table
     with your functions.  E.g.

       local M = {}
       ...
       function M.oink () ... end
       function M.barf () ... end
       ...
       return M
''

That seems pretty darn easy to me...

-Miles

-- 
I'm beginning to think that life is just one long Yoko Ono album; no rhyme
or reason, just a lot of incoherent shrieks and then it's over.  --Ian Wolff