lua-users home
lua-l archive

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

2009/9/7 Jim Jennings <>:
> (2a) Namespace control: Imports
> There are many ways to write Lua modules.  I like the ones that return the
> module table, so that I can choose the name for the table of functions
> provided by the module, e.g.
> rtype = require "recordtype"
> Unfortunately, not too many modules are written this way, because it can be
> awkward to do so.  A lot of modules create a table with a name that is fixed
> in the source code for the module.  In fact, modules that use the Lua module
> function do this.

That last point is not accurate. Modules that use the "module"
function don't have to use a fixed name when calling it. You can
simply forward the name passed to the module loader to the "module"
function. Most of my Lua modules start with this line:

module(..., package.seeall)

Either you knew it and you purposefully omitted to mention it, or you
didn't and in that case you may have underestimated the possibilities
of the existing Lua module system. In both cases something feels wrong
to me.