Skip to content

Instantly share code, notes, and snippets.

@0branch
Created August 27, 2011 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0branch/1175537 to your computer and use it in GitHub Desktop.
Save 0branch/1175537 to your computer and use it in GitHub Desktop.
check what's being exported into the global table by a given module
#!/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])
--------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment