summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-07-23 16:56:54 +0800
committerOpportunityLiu <[email protected]>2019-07-23 16:56:54 +0800
commitd7a716d699bd36045df0e18e5ba6cc9baf7b7ce6 (patch)
tree58a1e2b52a0667dfed13354f7df846c32c234f33
parent4457ae8bf300dd9b371435721b1f05251ce15134 (diff)
add loadfileimpl to loadfile
-rw-r--r--xmake/core/_xmake_main.lua44
1 files changed, 25 insertions, 19 deletions
diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua
index 343224ac7..afab0d128 100644
--- a/xmake/core/_xmake_main.lua
+++ b/xmake/core/_xmake_main.lua
@@ -31,23 +31,7 @@ xmake._PROJECT_DIR = _PROJECT_DIR
xmake._PROJECT_FILE = "xmake.lua"
xmake._WORKING_DIR = os.curdir()
--- init loadfile
-local _loadfile = _loadfile or loadfile
-local _loadcache = {}
-function loadfile(filepath)
-
- -- get absolute path
- filepath = path.absolute(filepath)
-
- -- attempt to load script from cache first
- local mtime = nil
- local cache = _loadcache[filepath]
- if cache and cache.script then
- mtime = os.mtime(filepath)
- if mtime > 0 and cache.mtime == mtime then
- return cache.script, nil
- end
- end
+local function loadfileimpl(filepath)
-- init displaypath
local binary = false
@@ -74,7 +58,29 @@ function loadfile(filepath)
file:close()
-- load script from string
- local script, errors = load(data, displaypath)
+ return load(data, displaypath)
+end
+
+-- init loadfile
+local _loadfile = _loadfile or loadfile
+local _loadcache = {}
+function loadfile(filepath)
+
+ -- get absolute path
+ filepath = path.absolute(filepath)
+
+ -- attempt to load script from cache first
+ local mtime = nil
+ local cache = _loadcache[filepath]
+ if cache and cache.script then
+ mtime = os.mtime(filepath)
+ if mtime > 0 and cache.mtime == mtime then
+ return cache.script, nil
+ end
+ end
+
+ -- load file
+ local script, errors = loadfileimpl(filepath)
if script then
_loadcache[filepath] = {script = script, mtime = mtime or os.mtime(filepath)}
end
@@ -84,7 +90,7 @@ end
-- init package path
table.insert(package.loaders, 2, function(v)
local filepath = xmake._PROGRAM_DIR .. "/core/" .. v .. ".lua"
- local script, serr = loadfile(filepath)
+ local script, serr = loadfileimpl(filepath)
if not script then
return "\n\tfailed to load " .. filepath .. " : " .. serr
end