summaryrefslogtreecommitdiff
path: root/xmake/scripts/base/preprocessor.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-03 09:29:35 +0800
committerruki <[email protected]>2015-06-03 09:29:35 +0800
commit08bba742c061c93f28c14499fa17af2f1edc2df8 (patch)
tree769eb97f37ada860b6e4c29f6ca247ccf70cbdbc /xmake/scripts/base/preprocessor.lua
parent03f445c175b2f8e4768bbff28065f935b9fe3201 (diff)
add private configure for preprocessor
Diffstat (limited to 'xmake/scripts/base/preprocessor.lua')
-rw-r--r--xmake/scripts/base/preprocessor.lua36
1 files changed, 34 insertions, 2 deletions
diff --git a/xmake/scripts/base/preprocessor.lua b/xmake/scripts/base/preprocessor.lua
index 235ae8011..10a64593b 100644
--- a/xmake/scripts/base/preprocessor.lua
+++ b/xmake/scripts/base/preprocessor.lua
@@ -79,7 +79,7 @@ function preprocessor._register(env, names, filter)
local _current = env._current
assert(_current)
- -- init ldflags
+ -- init the configure entry
_current[name] = _current[name] or {}
-- get arguments
@@ -109,7 +109,39 @@ function preprocessor._init(root, configures, scopes, filter, import)
-- enter new environment
local newenv = {}
local oldenv = getfenv()
- setmetatable(newenv, {__index = _G})
+ setmetatable(newenv, { __index = function(tbl, key)
+ -- private configure entry? we can get it directly and need not register it
+ if key and type(key) == "string" and key:startswith("__") then
+
+ return function(...)
+
+ -- check
+ local _current = newenv._current
+ assert(_current)
+
+ -- init the configure entry
+ _current[key] = _current[key] or {}
+
+ -- get arguments
+ local arg = arg or {...}
+ if table.getn(arg) == 0 then
+ -- no argument
+ _current[key] = nil
+ elseif table.getn(arg) == 1 then
+ -- save only one argument
+ _current[key] = preprocessor._filter(newenv, arg[1], filter)
+ else
+ -- save all arguments
+ for i, v in ipairs(arg) do
+ _current[key][i] = preprocessor._filter(newenv, v, filter)
+ end
+ end
+ end
+ end
+
+ -- get it from the global table
+ return rawget(_G, key)
+ end})
setfenv(1, newenv)
-- register all configures