Skip to content

Commit f4347fa

Browse files
committed
Support reset gloab variable
1 parent 1458132 commit f4347fa

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

Editor/defaultlua.lua

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
local function clearfile(path, needRequire)
1+
local function clearfile(path, needRequire, resetGValueOrName)
22
path = string.gsub(path, "[\\/]", ".")
33
path = string.gsub(path, "%.lua$", "")
4-
print(path)
4+
-- print(path)
55
package.loaded[path] = nil
6-
if needRequire then
7-
require(path)
6+
if not needRequire then return end
7+
8+
local gValName = resetGValueOrName
9+
if resetGValueOrName == true then
10+
gValName = string.gsub( path, ".*%.", "")
11+
end
12+
local gValue = gValName and _G[gValName]
13+
14+
require(path)
15+
16+
if gValue and type(gValue) == "table" then
17+
local newGVal = _G[gValName]
18+
if type(newGVal) == "table" then
19+
for k, v in pairs(newGVal) do
20+
if type(v) ~= "function" then
21+
newGVal[k] = v
22+
end
23+
end
24+
end
825
end
926
end
1027

0 commit comments

Comments
 (0)