lua-users home
lua-l archive

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


2008/9/13 Veli-Pekka Tätilä <vtatila@gmail.com>:
> [...]
> module( ..., package.seeall )
>
> The way I've understood it this will:
> * name and create your global module table (aka. class) after the physical
> file basename
> * make sure that "global" assignments incl. function  definitions go in your
> module table
> * fetch stuff from _G if it is not found in your module, when looking for
> "globals"
>
> The only disadvantage I've found is that I can no longer use the colon
> syntax. I would say:
>
> function class:setX(x)
>
> But now, it becomes:
>
> function setX(self, x)
>
> The self does feel quite cozy as a Perler, but would be even neater to omit
> that in the param list. The new module syntax makes the old syntactic sugar
> less sweet. But that's just cosmetic quibbling, <grin>.

This is based on the assumption that a module equals a class. I don't
think modules were necessarily meant to be used in that way.
Personally, I tend to view the module name as something like a
namespace. The namespace may contain just functions or entire classes,
depending on the design style for that particular project. But a
namespace containing functions (i.e. a module exposing functions) does
not necessarily equal a class, in my view. Hope I'm making sense.