lua-users home
lua-l archive

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


Roberto Ierusalimschy wrote:
But, until then, for me the main issue is to understand most of the
implications of my approach, i.e. writing a module with basic Lua
syntax, with clean, linear structure and no special support from
custom external functions (no "safe_require", "safe_module" or
similar).
And whether that kind of module could be robust, efficient, well
encapsulated, generally applicable, with no pitfalls (or with
well-known ones!), i.e "simple and foolproof", even if a bit verbose
(compared with other approaches like yours, which rely on an
additional framework).

I would say that now the "endorsed by the Lua team" way to write
modules is like this: using clean and basic Lua syntax.

-- Roberto


Thanks Roberto!
I'm glad to hear that my approach of writing modules is not simply a "poor newbie's" way to avoid too much conceptual load! :-)

Well if that will be the "endorsed standard", it becomes still more important for me to get feedback on my specific way of doing that (potential problems, limits, etc.).

On a related note, may I assume from what you said that now the standard contract for a module can be (incompletely) summarized as in the following lines?

1. when loaded and called, a module's chunk should return a table containing its "exported" symbols
2. a module should not create any global
3. ? any more items in the contract?

(BTW should this contract be the same for both Lua and C modules?)


Maybe laying down a well defined contract for a module could be useful to find a common ground (I see that this thing of 5.2 dumping "module" has stirred the water a little bit :-) )

I would add another point, which maybe is silly (sorry if it is "newbie noise") but: what is *really* a module?

Please don't beat me up! But I read many times on this list and the WIKI about different ways of loading a module, e.g. with "require" or directly using "loadfile" (or whatever).
So is a module simply a Lua file? I didn't find a clear answer.
Maybe because the term "module" is often overloaded?

If there is no clear definition of what a module is (i.e., what is its expected contract), I think it is difficult to talk about it with precision.

Take Java, for example, when you talk about a class it doesn't matter what different CS books say about the OO concept of a class. A _Java_class_ simply is what is defined in the Language specs. And it is a fairly different beast than a C++ class. So when talking about Java, a Java programmer has no doubt about what is meant with the term "class" in that context.

Well, when it comes to Lua, sometimes I get really puzzled by what is meant by the term "module". For a while I believed that a module was what is defined by the "module" function. Then I began reading more of the WIKI and this list, and I discovered that there are many different ways of _defining_ a module (the contract I mean, not its implementation, of course)!

I don't know really if this is good or bad (or maybe it's me that didn't understand the topic well), but I would feel a bit safer knowing there is a well defined entity behind the name "module".

Thank you all very much and sorry for the long post.

-- Lorenzo