summaryrefslogtreecommitdiff
path: root/test/globals.lua
blob: baa750493403ebbe3e41ee93a9d4a8e01c2b4aec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-- reads the output of luac -d -l -p and reports global variable usage
-- lines where a global is written to are marked with "*"
-- typical usage: luac -p -l file.lua | lua globals.lua | sort

local P="^.*; "		-- pattern to extract comments

while 1 do
	local s=read()
	if s==nil then return end
	if strfind(s,"%sGETGLOBAL") then
		local g=gsub(s,P,"")
		local _,_,l=strfind(s,"(%d+)")
		write(g,"\t",l,"\n")
	elseif strfind(s,"%sSETGLOBAL") then
		local g=gsub(s,P,"")
		local _,_,l=strfind(s,"(%d+)")
		write(g,"\t",l,"*\n")
	end
end