lua-users home
lua-l archive

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

On Feb 28, 2008, at 7:44 AM, Miles Bader wrote:

So, what exactly _is_ the recommended way to do this?

require() returns whatever the loaded code returns.

In the case of a module, this is usually a table. This is the most common case I would venture. For example, LHF has converted most (all?) of his many libraries to behave that way.

Other libraries might return just a function (e.g. Niklas Frykholm's excellent markdown.lua).

Or nothing. In which case require() will return a boolean to indicate that the library was indeed loaded... somewhere... usually in _G...

All in all... quiet a diversity of behaviors...

That said, I personally tend to only deal with modules that return a table and don't pollute the global namespace recklessly. If they behave differently, they better need a good reason and/or add quiet a bit of value (e.g. Niklas' markdown.lua).

When all is said and done, you can easily wrap any offending library as a table if you which to normalize the return value of require().