lua-users home
lua-l archive

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


Well, there is a bit of a hiccup, because Lua creates implicit "shadowed" locals anytime you write nested for loops.

But, I suppose such cases are easily identified -- they'll be overlaps between locals with names that aren't legal ids -- things like "(for generator)".  

If the behavior you want is to emit an error in response to something like Steve's shadow.lua, hooking into the parser to turn such situations into compile time errors would be fairly straightforward.  I'd suggest performing a check after each call to adjustlocalvars()  -- iterating through the local variable list, and checking that the new locals have startpc's higher than the endpc's of any locals that share the same name.

I'm still not convinced it's a great idea though :)  As the nested for loop case illustrates; there are perfectly valid reasons for Lua programmers to use shadowed locals.  So if you do write a patch for it, I'd certainly make it something that can be turned on and off via a debug function.

-Sven