Created
August 27, 2011 16:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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