#!/usr/bin/env lua local function usage() print ([[Lua static checker Usage: ]] .. arg[0]:match('/?([^/]+)$') .. [[ LUASOURCE Detects read/write accesses to undeclared globals.]]) end if #arg < 1 then usage() os.exit() end local globals = { assert = true, collectgarbage = true, dofile = true, error = true, _G = true, getfenv = true, getmetatable = true, ipairs = true, load = true, loadfile = true, loadstring = true, next = true, pairs = true, pcall = true, print = true, rawequal = true, rawget = true, rawset = true, select = true, setfenv = true, setmetatable = true, tonumber = true, tostring = true, type = true, unpack = true, _VERSION = true, xpcall = true, module = true, package = true, require = true, coroutine = true, debug = true, io = true, math = true, os = true, string = true, table = true, } for _, v in ipairs(arg) do print('==> ' .. v) local p = io.popen('luac -p -l -- ' .. v) for m in p:lines() do if m:match('ETTABUP.*_ENV') then local line, op, field = m:match('(%[[%d]+%]).*(.)ETTABUP.*"([_%w]+)"') if not globals[field] then if op == 'G' then op = '<-' else op = '->' end print(line, op, field) end end end p:close() end