lua-users home
lua-l archive

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


On Fri, Aug 30, 2013 at 7:41 AM, Philipp Kraus
<philipp.kraus@tu-clausthal.de> wrote:
> In C++ I use namespaces and each namespace is mapped to a directory in the filesystem. Can I create anything similar with Lua?

Lua's module system is hierarchical, and directly related to the
directory structure.

So if $LUA is where your modules usually sit, then $LUA/libs/mine.lua
will be accessible with require 'libs.mine'. This gives your modules a
(hopefully unqiue!) namespace or 'package' libs.

It's common to put larger classes each in their own module, and then
require 'libs.klass' will usually return the 'constructor' for the
class 'klass'