lua-users home
lua-l archive

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

On Sun, 16 Jan 2005 12:13:35 +0000
duck <> wrote:

> > A way to require (at compile-time) that variables be "declared"
> > (assigned a value) before use, like Perl's 'use strict'.
> See /test/undefined.lua in the 5.0.2 distro for a simple way
> of catching this sort of error, at least after a fashion.
> Not compile-time, but it surely helps...

Thanks for the info, everyone.

For a compile-time solution to this, I pondered it some more after
writing, and came up with the idea of a 'global' keyword, complementing
'local', which tells the compiler that the following variables are
lexically globals - either new ones, in which case 'global' means
something like 'declare', or ones already defined by code that is
compiling this code (by e.g. dofile()), in which case 'global' means
something more like 'import'.

Then just disallow any reference to a variable that hasn't been listed
in either a 'local' or a 'global'.

Looks like the linter does the equivalent of this, though, so it's
probably not necessary in the language itself.