diff options
| author | ruki <[email protected]> | 2018-05-05 00:42:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-05-04 22:12:14 +0800 |
| commit | 3567313cb859aa88e71ef9aa84e484f09fbccce8 (patch) | |
| tree | 315ceac7102e8b09cd654f813fd58afc14afb603 /xmake/core/base/interpreter.lua | |
| parent | 95af67cc06c76559599b79cfd057b1253bfdc95c (diff) | |
add values api to target
Diffstat (limited to 'xmake/core/base/interpreter.lua')
| -rw-r--r-- | xmake/core/base/interpreter.lua | 83 |
1 files changed, 76 insertions, 7 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index c04ad5d21..79c782842 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -989,9 +989,6 @@ end -- function interpreter:api_register_set_values(scope_kind, ...) - -- check - assert(self) - -- define implementation local implementation = function (self, scope, name, ...) @@ -1024,9 +1021,6 @@ end -- register api for add_values function interpreter:api_register_add_values(scope_kind, ...) - -- check - assert(self) - -- define implementation local implementation = function (self, scope, name, ...) @@ -1056,6 +1050,82 @@ function interpreter:api_register_add_values(scope_kind, ...) self:_api_register_xxx_values(scope_kind, "add", implementation, ...) end +-- register api for set_keyvalues +-- +-- interp:api_register_set_keyvalues("scope_kind", "name1", "name2", ...) +-- +-- api: +-- set_$(name1)("key", "value1") +-- set_$(name2)("key", "value1", "value2", ...) +-- +function interpreter:api_register_set_keyvalues(scope_kind, ...) + + -- define implementation + local implementation = function (self, scope, name, key, ...) + + -- get extra config + local values = {...} + local extra_config = values[#values] + if table.is_dictionary(extra_config) then + table.remove(values) + else + extra_config = nil + end + + -- save values + name = name .. "." .. key + scope[name] = values + + -- save extra config + if extra_config then + scope["__extra_" .. name] = scope["__extra_" .. name] or {} + local extrascope = scope["__extra_" .. name] + for _, value in ipairs(values) do + extrascope[value] = extra_config + end + end + end + + -- register implementation + self:_api_register_xxx_values(scope_kind, "set", implementation, ...) +end + +-- register api for add_keyvalues +-- +-- interp:api_register_add_keyvalues("scope_kind", "name1", "name2", ...) +-- +function interpreter:api_register_add_keyvalues(scope_kind, ...) + + -- define implementation + local implementation = function (self, scope, name, key, ...) + + -- get extra config + local values = {...} + local extra_config = values[#values] + if table.is_dictionary(extra_config) then + table.remove(values) + else + extra_config = nil + end + + -- save values + name = name .. "." .. key + scope[name] = table.join2(scope[name] or {}, values) + + -- save extra config + if extra_config then + scope["__extra_" .. name] = scope["__extra_" .. name] or {} + local extrascope = scope["__extra_" .. name] + for _, value in ipairs(values) do + extrascope[value] = extra_config + end + end + end + + -- register implementation + self:_api_register_xxx_values(scope_kind, "add", implementation, ...) +end + -- register api for set_array function interpreter:api_register_set_array(scope_kind, ...) @@ -1086,7 +1156,6 @@ function interpreter:api_register_add_array(scope_kind, ...) -- append array? scope[name] = scope[name] or {} table.insert(scope[name], {...}) - end -- register implementation |
