summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-02-14 19:42:39 +0800
committerruki <[email protected]>2016-02-15 19:10:27 +0800
commite056e25f57d12010ad5c5db4d6abd64e3450643f (patch)
tree81dbb88ee3b3585265ec70af36cbb032171df783
parentd18b7f588a8887644d53cb5f044589085097f98e (diff)
optimizate to import api for sandbox
-rw-r--r--xmake/core/base/sandbox.lua21
-rw-r--r--xmake/core/sandbox/builtin/import.lua52
-rw-r--r--xmake/core/sandbox/project.lua (renamed from xmake/core/sandbox/builtin/project.lua)0
3 files changed, 52 insertions, 21 deletions
diff --git a/xmake/core/base/sandbox.lua b/xmake/core/base/sandbox.lua
index 62b86b6fe..8654e6290 100644
--- a/xmake/core/base/sandbox.lua
+++ b/xmake/core/base/sandbox.lua
@@ -72,24 +72,6 @@ function sandbox._traceback(errors)
return results
end
--- import module
-function sandbox._api_builtin_import(self, module)
-
- -- import
- return require("sandbox/" .. module)
-end
-
--- register api
-function sandbox._api_register(self, name, func)
-
- -- check
- assert(self and self._PUBLIC)
- assert(name and func)
-
- -- register it
- self._PUBLIC[name] = function (...) return func(self, ...) end
-end
-
-- register api for builtin
function sandbox._api_register_builtin(self, name, func)
@@ -139,9 +121,6 @@ function sandbox._init()
end
end
- -- register import() for importing the extensional sandbox modules
- self:_api_register("import", sandbox._api_builtin_import)
-
-- save self
setmetatable(self._PUBLIC, { __index = function (tbl, key)
if type(key) == "string" and key == "_SANDBOX" and rawget(tbl, "_SANDBOX_READABLE") then
diff --git a/xmake/core/sandbox/builtin/import.lua b/xmake/core/sandbox/builtin/import.lua
new file mode 100644
index 000000000..ccbef0052
--- /dev/null
+++ b/xmake/core/sandbox/builtin/import.lua
@@ -0,0 +1,52 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file import.lua
+--
+
+-- load modules
+local utils = require("base/utils")
+
+-- import module
+function sandbox_builtin_import(name)
+
+ -- load module
+ local module = require("sandbox/" .. name)
+ if not module then
+ utils.error("cannot import module: %s", name)
+ utils.abort()
+ end
+
+ -- get the parent scope
+ local scope_parent = getfenv(2)
+ assert(scope_parent)
+
+ -- this module has been imported?
+ if rawget(scope_parent, name) then
+ utils.error("this module: %s has been imported!", name)
+ utils.abort()
+ end
+
+ -- import this module into the parent scope
+ scope_parent[name] = module
+end
+
+-- load module
+return sandbox_builtin_import
+
diff --git a/xmake/core/sandbox/builtin/project.lua b/xmake/core/sandbox/project.lua
index f3f726c6f..f3f726c6f 100644
--- a/xmake/core/sandbox/builtin/project.lua
+++ b/xmake/core/sandbox/project.lua