lua-users home
lua-l archive

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

On Thu, Jul 8, 2010 at 6:45 PM, Mark Hamburg <> wrote:
> For example, the vast majority of the code I write outside of interactive mode would be simpler with the addition of a simple import statement:
>        import foo
> which translates into:
>        local foo = require "foo"

That would be useful; it's very easy to do a token-filter for this
kind of sugar. Except that 'import' should be reserved for this kind
of construct:

import setmetatable,type from _G

expanded as

local setmetatable,type = _G.setmetatable,_G.type

which is also a very common pattern in modules.

So then we could have 'requires', which works like your 'import'
except that it takes multiple modules

requires foo, bar, math, io

However, there is a problem.  require() is not guaranteed to return
the module, it may well just return 'true' if the module writer has
not followed recommended practice.  This is particularly an issue if
'requires' was actually part of the language, and pretty much
guarantees that it will not ;)

Thinking about the problem of globals, I'd say that the great majority
of globals are modules, especially if module() has been used
consistently; actual 'global' variables are accessed within the
namespace of their defining module.

It would be very useful if the development environment flagged
undeclared globals as 'spelling mistakes'.  The InteliJ and Eclipse
Lua projects are promising;  this clearly needs static analysis as
both David and Mark have emphasized. My next project will be to bring
this sort of goodness to SciTE, which tends to be a little more nimble
and less bureaucratic than the big boys ;)

Another point about making the IDE work harder is that it can generate
necessary scaffolding as needed, an approach which has saved many a
Java Eclipse programmer from repetitive strain injury.  E.g, the
environment sees that you have just used setmetatable (a known global)
in module scope; it will then ensure that a 'local
setmetatable=setmetatable' declaration is inserted at the start of the
file.  This will make it easier for people to give up their
package.seeall addiction.

steve d.