From e056e25f57d12010ad5c5db4d6abd64e3450643f Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 14 Feb 2016 19:42:39 +0800 Subject: optimizate to import api for sandbox --- xmake/core/base/sandbox.lua | 21 ---------- xmake/core/sandbox/builtin/import.lua | 52 ++++++++++++++++++++++++ xmake/core/sandbox/builtin/project.lua | 73 ---------------------------------- xmake/core/sandbox/project.lua | 73 ++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 94 deletions(-) create mode 100644 xmake/core/sandbox/builtin/import.lua delete mode 100644 xmake/core/sandbox/builtin/project.lua create mode 100644 xmake/core/sandbox/project.lua 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 http://www.gnu.org/licenses/ +-- +-- 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/builtin/project.lua deleted file mode 100644 index f3f726c6f..000000000 --- a/xmake/core/sandbox/builtin/project.lua +++ /dev/null @@ -1,73 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file project.lua --- - --- define module: project -local project = project or {} - --- load modules -local rule = require("base/rule") -local config = require("base/config") - --- get the build directory -function project.buildir() - - -- get it - return config.get("buildir") -end - --- get the project directory -function project.projectdir() - - -- get it - return xmake._PROJECT_DIR -end - --- get the log file -function project.logfile() - - -- get it - return rule.logfile() -end - --- get the current platform -function project.plat() - - -- get it - return config.get("plat") -end - --- get the current architecture -function project.arch() - - -- get it - return config.get("arch") -end - --- get the current mode -function project.mode() - - -- get it - return config.get("mode") -end - --- return module: project -return project diff --git a/xmake/core/sandbox/project.lua b/xmake/core/sandbox/project.lua new file mode 100644 index 000000000..f3f726c6f --- /dev/null +++ b/xmake/core/sandbox/project.lua @@ -0,0 +1,73 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file project.lua +-- + +-- define module: project +local project = project or {} + +-- load modules +local rule = require("base/rule") +local config = require("base/config") + +-- get the build directory +function project.buildir() + + -- get it + return config.get("buildir") +end + +-- get the project directory +function project.projectdir() + + -- get it + return xmake._PROJECT_DIR +end + +-- get the log file +function project.logfile() + + -- get it + return rule.logfile() +end + +-- get the current platform +function project.plat() + + -- get it + return config.get("plat") +end + +-- get the current architecture +function project.arch() + + -- get it + return config.get("arch") +end + +-- get the current mode +function project.mode() + + -- get it + return config.get("mode") +end + +-- return module: project +return project -- cgit v1.3.1