lua-users home
lua-l archive

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


Hi all,

This is an extended version of David Manura's globalsplus.lua
described in http://lua-users.org/wiki/DetectingUndefinedVariables

It invokes luac for you, so it passes on any compile errors.  Puts out
warnings in same error format so will work out of the box with editors
which understand Lua error messages already.  There is a -t flag for
'tolerant' where it will call any requires for you and regard globals
defined in the file as ok, and there is support for extending the
whitelist of known globals. This version also marks any write of a
known global or subfield as an error (so both 'next = 1' and 'function
table.new() .. end' are flagged as 'errors')

Not a perfect solution, and I can't guarantee the occaisional false
positive, but with good local discipline it's a good way to find
errors before actually running programs, I've already found some
sneaky little issues in my codebases using it.  (Most people with big
Lua codebases use something like this)

Find it here https://gist.github.com/4602636

Can be adapted to work with Lua 5.2 opcodes as well, if there's interest.

steve d.