Skip to content

Commit

Permalink
Add -o/--omit-standard option
Browse files Browse the repository at this point in the history
  • Loading branch information
snogglethorpe committed Apr 2, 2012
1 parent f767968 commit 85515a5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions globals.lua
Expand Up @@ -8,6 +8,9 @@
local _G,arg,io,ipairs,os,string,table,tonumber
= _G,arg,io,ipairs,os,string,table,tonumber
-- if true, omit standard globals
local omit_standard = false
local function process_file(filename, luac, luavm_ver)
local global_list = {} -- global usages {{name=, line=, op=''},...}
local name_list = {} -- list of global names
Expand All @@ -25,6 +28,9 @@ local function process_file(filename, luac, luavm_ver)
else -- assume 5.1
ok,_,l,op,g=string.find(s,'%[%-?(%d*)%]%s*([GS])ETGLOBAL.-;%s+(.*)$')
end
if ok and omit_standard and _G[g] then
ok = false
end
if ok then
if op=='S' then op='s' else op='' end -- s means set global
table.insert(global_list, {name=g, line=tonumber(l), op=op})
Expand Down Expand Up @@ -70,7 +76,8 @@ if not arg[1] then
io.write(
table.concat({
'globals.lua - list global variables in Lua files',
'usage: globals.lua <inputfiles>',
'usage: globals.lua [<option>...] <inputfiles>',
" -o, --omit-standard : Don't show standard symbols",
' <inputfiles> : list of Lua files ',
'',
" environment variable 'LUAC' overrides name of 'luac'",
Expand All @@ -85,6 +92,10 @@ local luavm_ver = fd:read():match('Lua (%d.%d)')
for i = 1, select ('#', ...) do
local filename = select (i, ...)
io.write('\n'..filename..'\n')
process_file( filename , luac, luavm_ver)
if filename == '-o' or filename == '--omit-standard' then
omit_standard = true
else
io.write('\n'..filename..'\n')
process_file( filename , luac, luavm_ver)
end
end

0 comments on commit 85515a5

Please sign in to comment.