From 0c18d736a83454c5e0714d90c9dd58b2114a60f6 Mon Sep 17 00:00:00 2001 From: tacheometry <39647014+tacheometry@users.noreply.github.com> Date: Sun, 26 Dec 2021 15:06:36 +0200 Subject: [PATCH] Fix _G working improperly when hot reloading --- plugin/src/hotReload.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/src/hotReload.lua b/plugin/src/hotReload.lua index 5dbfb24..a38c69f 100644 --- a/plugin/src/hotReload.lua +++ b/plugin/src/hotReload.lua @@ -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) @@ -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