code organization

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

code organization

Philipp Kraus-2
Hello,

do you know some "practical" tips for organization Lua code?
I use a class structure, so I would like to store each class with the method in a file. Modules are also stored in a file.
Both files can be included with require.

In C++ I use namespaces and each namespace is mapped to a directory in the filesystem. Can I create anything similar with Lua?

Thanks a lot

Phil
Reply | Threaded
Open this post in threaded view
|

Re: code organization

steve donovan
On Fri, Aug 30, 2013 at 7:41 AM, Philipp Kraus
<[hidden email]> 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'