Skip to content

Commit

Permalink
Fix _G working improperly when hot reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
tacheometry committed Dec 26, 2021
1 parent f91e028 commit 0c18d73
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion plugin/src/hotReload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ local function assertf(c, m, ...)
end

local loading, ERR = {}, {}
local globalTable = {}

function hotReload.flush()
table.clear(loading)
table.clear(globalTable)
end

function hotReload.require(mod)
Expand All @@ -32,7 +34,10 @@ function hotReload.require(mod)
local env = setmetatable({
script = mod,
require = hotReload.require,
}, { __index = getfenv() })
_G = globalTable,
}, {
__index = getfenv(),
})
s, e = pcall(setfenv(s, env))
if not s then
loading[mod] = ERR
Expand Down

0 comments on commit 0c18d73

Please sign in to comment.