lua-users home
lua-l archive

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


I've observed three naming conventions for the top-level source file of a Lua package, where '?' represents the name of the package: "?.lua", "?/?.lua", and "?/init.lua". The first and third conventions are supported by the default package.path in Lua 5.1. The first is used in the Kepler binary distribution (at least on Windows), and the second is used in the source trees of Kepler packages like CGILua and Xavante. I haven't yet seen anyone else use the third, though I use it myself.

Which is best? I'm especially curious to know why the Kepler project uses different naming conventions in its source and binary distributions, and why its source trees use a naming convention that Lua's default configuration doesn't support.

I prefer "?/init.lua" because it most closely follows the DRY (Don't Repeat Yourself) principle. With this convention, a package's directory tree looks like this:

xavante/
  init.lua
  httpd.lua
  ...

instead of this:

xavante.lua
xavante/
  httpd.lua
  ...

or this:

xavante/
  xavante.lua
  httpd.lua
  ...

While I'm using the Kepler project as an example here, I post this to the Lua list because the subject is relevant to the Lua community at large.

Matt