diff options
| author | ruki <[email protected]> | 2017-07-19 21:12:51 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-19 21:12:51 +0800 |
| commit | 1ea7269e5078041df9c170b020953273ea176675 (patch) | |
| tree | cade92c9dd13d9bc69f62007d5f41f717c4124ff /xmake/core/base/global.lua | |
| parent | 2b52ec7d069e2a5b297b52f6696f70f3d53ff385 (diff) | |
fix config and add readonly mode
Diffstat (limited to 'xmake/core/base/global.lua')
| -rw-r--r-- | xmake/core/base/global.lua | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/xmake/core/base/global.lua b/xmake/core/base/global.lua index 3bf93bde7..823603722 100644 --- a/xmake/core/base/global.lua +++ b/xmake/core/base/global.lua @@ -37,31 +37,45 @@ function global._file() return path.join(global.directory(), "xmake.conf") end --- get the current given configure from +-- get the current given configure function global.get(name) - -- get configs - local configs = global._CONFIGS or {} - - -- the value - local value = configs[name] - if type(value) == "string" and value == "auto" then - value = nil + -- get it + local value = nil + if global._CONFIGS then + value = global._CONFIGS[name] + if type(value) == "string" and value == "auto" then + value = nil + end end -- get it return value end --- set the current given configure -function global.set(name, value) +-- this global name is readonly? +function global.readonly(name) + return global._MODES and global._MODES["__readonly_" .. name] +end + +-- set the given configure to the current +function global.set(name, value, readonly) - -- get configs - local configs = global._CONFIGS or {} - global._CONFIGS = configs + -- check + assert(name) + + -- check readonly + assert(not global.readonly(name), "cannot set readonly global: " .. name) -- set it - configs[name] = value + global._CONFIGS = global._CONFIGS or {} + global._CONFIGS[name] = value + + -- mark as readonly + if readonly then + global._MODES = global._MODES or {} + global._MODES["__readonly_" .. name] = true + end end -- get all options |
