lua-users home
lua-l archive

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


This is about a small module I wrote for people like me who just don't
like the way Lua handles global variables. It can register and work with
other modules, so it will also flag stuff like

e=string.exit -- no exit in string

The module is loosely based on the code in etc/strict.lua (however, if
anything doesn't work that's entirely my fault). It's part of a bigger
project so not all functionality will appeal to all people.

I am pretty new to Lua, so there may be "non-compliant" code or even
hair-raising bugs. If so, please tell me.

To keep the posting readable I've not included any code. The module and 
some usage examples (as well as an archive with all files) can be found
here:

http://thomaslauer.com/comp/LuaStrict
http://thomaslauer.com/comp/LuaStrict_Example_Code
http://thomaslauer.com/download/luastrict.7z

Last but not least, two questions.

1. If someone tells me where in the lua-users wiki this sort of thing
goes, I'll post the stuff there as well.

2. If you look at the code, you'll see that Strict works by setting the
__newindex and __index entries in the relevant metatables (like the
original strict.lua does for the global table).

That's all well and good but it means that I blindly overwrite whatever
handler someone else may have already installed there. OTOH, most code
I've seen in connection with __newindex and __index does just that:
there's no attempt to "daisy-chain" these handlers. For example, my code
could conceivably call the previous handlers and, if those somehow
"deliver the goods", not flag the variable in question as being
undeclared.

I think this shouldn't be overly difficult to implement but as I have
not yet seen an implementation I am perhaps wrong. Any thoughts?

Anyway, give it a whirl.

-- 
cheers  thomasl

web : http://thomaslauer.com/start