Imported from ../lua-3.1.tar.gz.
[lua.git] / test / globals.lua
blob03b977c3bece04d4d9d2519d6876b49764ba40ce
1 -- globals.lua
2 -- reads the output of luac -d -l -p and reports global variable usage
3 -- typical usage: luac -p -l -d file.lua | lua globals.lua | sort
5 local P="^.*; " -- pattern to extract comments
6 local l="" -- last line seen
8 while 1 do
9 local s=read()
10 if s==nil then return end
11 if strfind(s,"%sSETLINE") then
12 l=gsub(s,P,"")
13 elseif strfind(s,"%sGETGLOBAL") then
14 local g=gsub(s,P,"")
15 write(g,"\t",l,"\n")
16 elseif strfind(s,"%sSETGLOBAL") then
17 local g=gsub(s,P,"")
18 write(g,"*\t",l,"\n")
19 end
20 end