lua-users home
lua-l archive

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




On Fri, Jul 9, 2010 at 8:41 PM, Henk Boom <henk@henk.ca> wrote:
On 9 July 2010 04:45, Fabien <fleutot+lua@gmail.com> wrote:
> On Fri, Jul 9, 2010 at 12:16 AM, Henk Boom <henk@henk.ca> wrote:
>> I would love for all variables would be statically and
>> lexically scoped, so that the compiler could generate compile-time
>> error messages for undeclared variables.
> Not reliably: since require() is a regular function call on a regular global
> var, it can be constructed in arbitrarily complex ways.

I was thinking of replacing require with a macro which would declare
static variables for imported names, something like the way PLT-Scheme
does it. It requires that you know what names a serving module
provides when you're compiling the client module though.

There's a sample doing pretty much this in metalua. As you noticed, it needs to get some declarations, and does this by defining a declaration DSL and looking for declaration files in configurable paths. It parses non-pathological 'require' invocations automatically, too:

       http://github.com/fab13n/metalua/tree/master/src/samples/metalint/