summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-04-07 11:02:35 +0800
committerruki <[email protected]>2016-04-07 11:02:35 +0800
commita684950c450b7490f3a95c2200cd1943a30a4272 (patch)
tree5b4d6ba1a46963ddfeb0a70e4821753be8fecc09
parent81d1395ba00c3144a8ebf2f57a869c44c930c5f0 (diff)
import instance
-rwxr-xr-xxmake/actions/config/main.lua6
-rw-r--r--xmake/core/sandbox/modules/import.lua24
2 files changed, 22 insertions, 8 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 6d80a4a03..ec4334196 100755
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -22,11 +22,11 @@
-- imports
import("core.base.option")
-import("core.project.cache")
import("core.project.config")
import("core.project.global")
import("core.project.project")
import("core.platform.platform")
+import("core.project.cache", {instance = "local.build"})
import("config_h")
import("makefile")
@@ -110,8 +110,8 @@ function main()
end
-- need rebuild it
- cache("local.build"):set("rebuild", true)
- cache("local.build"):flush()
+ cache:set("rebuild", true)
+ cache:flush()
-- save the project configure
config.save(targetname)
diff --git a/xmake/core/sandbox/modules/import.lua b/xmake/core/sandbox/modules/import.lua
index 00669bd15..9be583544 100644
--- a/xmake/core/sandbox/modules/import.lua
+++ b/xmake/core/sandbox/modules/import.lua
@@ -222,28 +222,34 @@ end
-- import("core.platform")
-- => platform
--
--- import("core.platform", "p")
+-- import("core.platform", {alias = "p"})
-- => p
--
-- import("core")
-- => core
-- => core.platform
---
--- import("core", nil, "/scripts")
+-- import("core", {rootdir = "/scripts"})
-- => core
-- => core.platform
--
-function sandbox_import.import(name, alias, rootdir)
+-- import("core.project.cache", {instance = "local.build"})
+-- => cache == cache("local.build")
+--
+function sandbox_import.import(name, args)
-- check
assert(name)
+ -- the arguments
+ args = args or {}
+
-- get the current sandbox instance
local instance = sandbox.instance()
assert(instance)
-- the root directory for this sandbox script
- local rootdir = rootdir or instance:rootdir()
+ local rootdir = args.rootdir or instance:rootdir()
assert(rootdir)
-- load module
@@ -262,6 +268,14 @@ function sandbox_import.import(name, alias, rootdir)
raise("cannot import module: %s, %s", name, errors)
end
+ -- init module instance
+ if args.instance and type(module) == "function" then
+ module = module(args.instance)
+ if not module then
+ raise("cannot construct module: %s, %s", name, errors)
+ end
+ end
+
-- get module name
local modulename = sandbox_import._modulename(name)
if not modulename then
@@ -278,7 +292,7 @@ function sandbox_import.import(name, alias, rootdir)
end
-- import this module into the parent scope
- scope_parent[alias or modulename] = module
+ scope_parent[args.alias or modulename] = module
-- return it
return module