project/gcheck/gcheck.lua

#!/usr/bin/env lua
--------------------------------------------------------------------------------
--              _               _    
--    __ _  ___| |__   ___  ___| | __
--   / _` |/ __| '_ \ / _ \/ __| |/ /
--  | (_| | (__| | | |  __/ (__|   < 
--   \__, |\___|_| |_|\___|\___|_|\_\
--   |___/                           
--
--  Check what's being exported into the global table by a given module.
--------------------------------------------------------------------------------

local hr    = function(n) print(("-"):rep(n)) end

local diff  = function(f, t)
  hr(75)
  print("  The following global values differ after loading '" .. f .. "'")
  hr(75)
  for k,v in pairs(_G) do
    if ( t[k] ~= _G[k] ) then
      io.write(string.format("%20s = %-25s [was: %s]\n", tostring(k), tostring(v), tostring(t[k])))
    end
  end
  hr(75)
end

local prep  = function()
  local t = {}
  for k,v in pairs(_G) do t[k] = v end
  return t
end

local check  = function(mod)
  local orig = prep();
  require(mod)
  diff(mod, orig)
end

--------------------------------------------------------------------------------

if ( not arg[1] ) then
  print("You didn't supply a module name.")
  os.exit(1)
end

check(arg[1])

--------------------------------------------------------------------------------

download original