[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: S.W.O.T analysis
- From: Miles Bader <miles@...>
- Date: Fri, 21 Oct 2011 14:01:51 +0900
"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