From da7bc7414f499ec3420c1d1e062a8913b88935b7 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 15 Mar 2016 14:04:16 +0800 Subject: fix import bug --- xmake/core/sandbox/modules/import.lua | 41 +++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/xmake/core/sandbox/modules/import.lua b/xmake/core/sandbox/modules/import.lua index abee9d999..0577097ed 100644 --- a/xmake/core/sandbox/modules/import.lua +++ b/xmake/core/sandbox/modules/import.lua @@ -101,6 +101,36 @@ function sandbox_import._loadfile(filepath, instance) return result end +-- find module +function sandbox_import._find(dir, name) + + -- check + assert(dir and name) + + -- replace "package.module" => "package/module" + name = (name:gsub("%.", "/")) + assert(name) + + -- load the single module? + local module = nil + if os.isfile(path.join(dir, name .. ".lua")) then + + -- ok + return true + + -- load modules + elseif os.isdir(path.join(dir, name)) then + + -- ok + return true + + end + + -- not found + return false + +end + -- load module function sandbox_import._load(dir, name, instance) @@ -211,16 +241,19 @@ function sandbox_import.import(name, alias) local rootdir = instance:rootdir() assert(rootdir) - -- load module from the sandbox root directory first - local module, errors = sandbox_import._load(rootdir, name, instance) - if not module then + -- load module + local module = nil + local errors = nil + if sandbox_import._find(rootdir, name) then + -- load module from the sandbox root directory + module, errors = sandbox_import._load(rootdir, name, instance) + else -- load module from the sandbox core directory module, errors = sandbox_import._load(path.join(xmake._CORE_DIR, "sandbox/modules/import"), name) end -- check if not module then - print(errors) os.raise("cannot import module: %s, %s", name, errors) end -- cgit v1.3.1