Skip to content

Commit 8142877

Browse files
committed
Update defaultlua.lua
1 parent f4347fa commit 8142877

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

Editor/defaultlua.lua

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1-
local function clearfile(path, needRequire, resetGValueOrName)
1+
local clearfile
2+
local path2chunkname
3+
local mt = {}
4+
local globalT = setmetatable({}, mt)
5+
mt.__index = function(t, k)
6+
if k == "clearfile" then
7+
return clearfile
8+
elseif k == "path2chunkname" then
9+
return path2chunkname
10+
else
11+
return _G[k]
12+
end
13+
end
14+
15+
path2chunkname = function(path)
216
path = string.gsub(path, "[\\/]", ".")
317
path = string.gsub(path, "%.lua$", "")
18+
return path
19+
end
20+
21+
clearfile = function(path, needRequire, resetGValueOrName)
22+
path = path2chunkname(path)
423
-- print(path)
524
package.loaded[path] = nil
625
if not needRequire then return end
726

827
local gValName = resetGValueOrName
928
if resetGValueOrName == true then
10-
gValName = string.gsub( path, ".*%.", "")
29+
gValName = string.gsub(path, ".*%.", "")
1130
end
1231
local gValue = gValName and _G[gValName]
1332

@@ -25,5 +44,12 @@ local function clearfile(path, needRequire, resetGValueOrName)
2544
end
2645
end
2746

47+
local function _loadfile(path)
48+
local chunk = loadfile(path)
49+
if chunk then
50+
setfenv(chunk, globalT)()
51+
end
52+
end
53+
2854
-- do anything
2955

0 commit comments

Comments
 (0)