lua-users home
lua-l archive

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


David Given <dg@cowlark.com> wrote:
<heavy snippage>
- the module structure is a pain when writing single applications ---
because once you've done module(), the standard library is no longer
available. You have to import everything with 'local print = print'
statements. And if you forget one you get no warnings or error messages
until it crashes at run time, either. Again, #include would have helped
with this. Eventually I gave up on modules.
Errm, maybe I'm missing something here, but couldn't you just say:

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>.

Hth.

--
With kind regards Veli-Pekka Tätilä
Accessibility, Apps and Coding plus Synths and Music:
http://vtatila.kapsi.fi