diff options
| author | ruki <[email protected]> | 2016-03-03 18:22:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-03-03 18:22:38 +0800 |
| commit | f4b82ec9289932937c21e00b0ff35bb4f3544e3b (patch) | |
| tree | 955064af810f8a0a9da03d0cb7574b3281bfd622 | |
| parent | c617361644a1856ffda5b0201b50f933d1f2f6cb (diff) | |
register scope for storage
| -rw-r--r-- | xmake/core/base/interpreter.lua | 26 | ||||
| -rw-r--r-- | xmake/core/base/storage.lua | 50 | ||||
| -rw-r--r-- | xmake/core/sandbox/sandbox.lua | 14 |
3 files changed, 45 insertions, 45 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 490da9405..2d3b7a7c0 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -419,35 +419,35 @@ end function interpreter.init() -- init an interpreter instance - local self = { _PUBLIC = {} + local instance = { _PUBLIC = {} , _PRIVATE = { _SCOPES = {} , _MTIMES = {}}} -- inherit the interfaces of interpreter for k, v in pairs(interpreter) do if type(v) == "function" then - self[k] = v + instance[k] = v end end -- register the builtin interfaces - self:api_register("add_subdirs", interpreter.api_builtin_add_subdirs) - self:api_register("add_subfiles", interpreter.api_builtin_add_subfiles) + instance:api_register("add_subdirs", interpreter.api_builtin_add_subdirs) + instance:api_register("add_subfiles", interpreter.api_builtin_add_subfiles) -- register the builtin interfaces for lua - self:api_register_builtin("print", print) - self:api_register_builtin("pairs", pairs) - self:api_register_builtin("ipairs", ipairs) - self:api_register_builtin("format", string.format) - self:api_register_builtin("printf", utils.printf) + instance:api_register_builtin("print", print) + instance:api_register_builtin("pairs", pairs) + instance:api_register_builtin("ipairs", ipairs) + instance:api_register_builtin("format", string.format) + instance:api_register_builtin("printf", utils.printf) -- register the builtin modules for lua - self:api_register_builtin("path", path) - self:api_register_builtin("table", table) - self:api_register_builtin("string", string) + instance:api_register_builtin("path", path) + instance:api_register_builtin("table", table) + instance:api_register_builtin("string", string) -- ok? - return self + return instance end -- load results diff --git a/xmake/core/base/storage.lua b/xmake/core/base/storage.lua index e633fd43d..60eb1343a 100644 --- a/xmake/core/base/storage.lua +++ b/xmake/core/base/storage.lua @@ -29,43 +29,43 @@ local io = require("base/io") local path = require("base/path") local utils = require("base/utils") --- init the storage instance +-- get root directory from the given scope name -- -- global: ~/.xmake -- output: projectdir/output -- project: projectdir/.xmake -- temporary: tmpdir/.xmake -function storage._init(rootdir) +function storage.rootdir(scopename) -end - --- the global storage instance -function storage.global() - - -- get it - return storage._init(path.translate("~/.xmake")) -end + -- init root directories + local rootdirs = + { + global = path.translate("~/.xmake") + , output = path.join(xmake._PROJECT_DIR, "output") + , project = path.join(xmake._PROJECT_DIR, ".xmake") + , temporary = path.join(os.tmpdir(), ".xmake") + } + storage._ROOTDIRS = storage._ROOTDIRS or {} --- the output storage instance -function storage.output() + -- get root directory from the given scope name + local rootdir = storage._ROOTDIRS[scopename] or rootdirs[scopename] + if not rootdir then + os.raise("unknown scope %s for storage!", scopename) + end - -- TODO - -- get it - return storage._init(path.join(xmake._PROJECT_DIR, "output")) + -- ok + return rootdir end --- the project storage instance -function storage.project() - - -- get it - return storage._init(path.join(xmake._PROJECT_DIR, ".xmake")) -end +-- register storage scope from the given root directory +function storage.register(scopename, rootdir) --- the temporary storage instance -function storage.temporary() + -- check + assert(scopename and rootdir) - -- get it - return storage._init(path.join(os.tmpdir(), ".xmake")) + -- register it + storage._ROOTDIRS = storage._ROOTDIRS or {} + storage._ROOTDIRS[scopename] = rootdir end -- return module diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua index 6245acb1c..96950ee0b 100644 --- a/xmake/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/sandbox.lua @@ -86,12 +86,12 @@ end function sandbox._init() -- init an sandbox instance - local self = {_PUBLIC = {}, _PRIVATE = {}} + local instance = {_PUBLIC = {}, _PRIVATE = {}} -- inherit the interfaces of sandbox for k, v in pairs(sandbox) do if type(v) == "function" then - self[k] = v + instance[k] = v end end @@ -115,7 +115,7 @@ function sandbox._init() end -- register module - self:_api_register_builtin(module_name, results) + instance:_api_register_builtin(module_name, results) else -- error os.raise(errors) @@ -123,10 +123,10 @@ function sandbox._init() end end - -- save self - setmetatable(self._PUBLIC, { __index = function (tbl, key) + -- save instance + setmetatable(instance._PUBLIC, { __index = function (tbl, key) if type(key) == "string" and key == "_SANDBOX" and rawget(tbl, "_SANDBOX_READABLE") then - return self + return instance end return rawget(tbl, key) end @@ -138,7 +138,7 @@ function sandbox._init() end}) -- ok? - return self + return instance end -- make sandbox instance with the given script |
