Skip to content

Instantly share code, notes, and snippets.

@mcd1992
Created September 15, 2014 14:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcd1992/845260a922fb6e9abe73 to your computer and use it in GitHub Desktop.
Save mcd1992/845260a922fb6e9abe73 to your computer and use it in GitHub Desktop.
function unrequire( modName )
if( not modName ) then return end
local _R = debug.getregistry()
local moduleMetatable = _R["_LOADLIB"]
package.loaded[ modName ] = nil
_G[ modName ] = nil
for k, ud in pairs( _R ) do
if( (type(k) == "string") and string.find( k, "^LOADLIB: .+gm.._" .. modName .. "_.+%.dll$" ) and (type(ud) == "_LOADLIB") and (getmetatable(ud) == moduleMetatable) ) then
print( "Unloading: " .. k )
moduleMetatable.__gc( _R[ k ] )
_R[ k ] = nil
_MODULES[ modName ] = nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment