lua-users home
lua-l archive

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

On 1 February 2018 at 21:34, Tim Hill <> wrote:
>> On Feb 1, 2018, at 8:41 AM, Sean Conner <> wrote:
>> It was thus said that the Great Dibyendu Majumdar once stated:
>>> Hi
>>> Sorry I should know the answer to this but I don't. Does Lua support dotted module names... i.e. map to directory path?
>>  You mean something like:
>>       net = require "" --?
>> If so, then yes, Lua does.
>>  -spc
> This cleanly solves the external namespace, assuming someone can promote some form of standardization around whatever convention is agreed (LuaRocks team???).

Rock names are first-come-first-serve, and projects can have their own
repository should they have namespace conflicts. As for module names,
my recommendations are to:

1) use top-level names that are as unique as possible (e.g. do not use
top-level module names such as "util")
2) not set any globals in modules.

# Unique names

People seem to want both obvious descriptive names and avoiding
namespace clashes. When these two desires conflict, I'd say the latter
is more important than the former. Having two incompatible modules
called "xml" is worse than having an XML parser called "teddybear".
(But remember you can always call your module "teddyxml" or

The name of a module shouldn't be an impediment to its
discoverability: does rock search by name and description
(and so do search engines :) ).

# Loading modules

I recommend the Lua 5.2+ pattern,

   local bar = require("")

to be always used, even for Lua 5.1. If globals are never used, then
the fact that Lua 5.1 creates globals becomes irrelevant. As for the
name of the local, I recommend always using the name of the final
component of the namespaced module. (It is _really_ annoying to switch
between different Lua codebases and have to keep going up and down
when reading the source to check how the modules are named, because,
say, someone decided to load "socket" as "skt"). In case of name
clashes in locals, I recommend a convention of disambiguating with _ :

   local bar = require("")
   local baz_bla = require("baz.bla")
   local quux_bla = require("quux.bla")

-- Hisham