lua-users home
lua-l archive

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

On Sunday 27 February 2005 22.16, Mark Hamburg wrote:
> For non-interactive code, what is probably more interesting is
> requiring that all variables be declared.
[...error hook...]

This stuff gets hairy rather quickly. (Or it's just me being more 
stupid than usual. :-)

EEL goes all the way in the other direction, basically, by keeping 
variables local (register frame variables by default, except in the 
top level of a module, where variables become 'static' - ie "module 
local") always requiring that variables are declared. The first 
assignment is considered the declaration, and is also the 
initialization. (There's a difference in some cases, as a result of 
the refcounting based memory management.)

The tricky part is avoiding a dummy initialization before code like 
        //y = 0;   // No, thanks!
        if a
                y = 1;
                y = 2;

The EEL compiler has an event system that keeps track of variable 
initializations, possible control flow paths and stuff. This is used 
for dead code elimination and various other compile time checks, as 
well as to ensure that you can't accidentally write something like:

        if a
                x = 1;
                y = 2;

and end up with either x or y being uninitialized. (That would 
potentially crash the VM, since it doesn't touch register frame/local 
variables at all before the first assignment.)

Some people seem to like the idea that you just get 0/nil/false or 
something when you read from an uninitialized variable, but 
personally, I have only bad experiences with that "feature" in the 
languages that have it... EEL doesn't require *explicit* 
declarations, but that's as far "lazy scripting" goes. There's no way 
that you can compile an EEL program that reads from an uninitialized 
variable - unless I've screwed up somewhere, that is. :-)

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
|  Free/Open Source audio engine for games and multimedia.  |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> -'
   --- --- ---