Last active
March 30, 2020 00:05
-
-
Save Henkoglobin/ced7f06d3e6bda643b8affffbddd12e2 to your computer and use it in GitHub Desktop.
Provides a function that can be used to reload all required modules.
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
local standard = {} | |
for k in pairs(package.loaded) do | |
standard[k] = true | |
end | |
function R() | |
local loadThese = {} | |
-- Unload all loaded packages... | |
for k in pairs(package.loaded) do | |
-- ... unless they're considered 'standard lib' | |
if not standard[k] then | |
-- Also save the old instance in order to replace global variable values | |
loadThese[k] = package.loaded[k] | |
package.loaded[k] = nil | |
end | |
end | |
for lib, prevLoaded in pairs(loadThese) do | |
-- Re-require the package | |
local loaded = require(lib) | |
-- Iterate all globals, if they match the old instance, replace the value | |
for name, value in pairs(_G) do | |
if value == prevLoaded then | |
_G[name] = loaded | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment