diff options
| author | ruki <[email protected]> | 2019-02-18 22:38:07 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-02-18 10:09:01 +0800 |
| commit | e1ab1e11d67af8fc4dfa76e3586a7531af87f777 (patch) | |
| tree | 6ef03dea3c082192a97ad3093cc0f8edcb042c9c | |
| parent | eb0674bb59e5d0b682bec1ade12ee976bcf658e5 (diff) | |
remove some unused functions
| -rw-r--r-- | xmake/core/base/interpreter.lua | 81 | ||||
| -rw-r--r-- | xmake/core/base/scopeinfo.lua | 57 |
2 files changed, 56 insertions, 82 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 94cea2979..6f32225e9 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -1184,87 +1184,6 @@ function interpreter:api_register_add_keyvalues(scope_kind, ...) self:_api_register_xxx_values(scope_kind, "add", implementation, ...) end --- register api for set_array -function interpreter:api_register_set_array(scope_kind, ...) - - -- check - assert(self) - - -- define implementation - local implementation = function (self, scope, name, ...) - - -- update array? - scope[name] = {} - table.insert(scope[name], {...}) - end - - -- register implementation - self:_api_register_xxx_values(scope_kind, "set", implementation, ...) -end - --- register api for add_array -function interpreter:api_register_add_array(scope_kind, ...) - - -- check - assert(self) - - -- define implementation - local implementation = function (self, scope, name, ...) - - -- append array? - scope[name] = scope[name] or {} - table.insert(scope[name], {...}) - end - - -- register implementation - self:_api_register_xxx_values(scope_kind, "add", implementation, ...) -end - --- register api for set_module -function interpreter:api_register_set_module(scope_kind, ...) - - -- check - assert(self) - - -- define implementation - local implementation = function (self, scope, name, modulename) - - -- is module name? - if type(modulename) ~= "string" then - os.raise("set_%s(): invalid module name!", name) - end - - -- import module as script - local script, errors = loadstring(string.format("import(\"%s\", {inherit = true})", modulename)) - if not script then - os.raise("set_%s(): %s", name, errors) - end - - -- make sandbox instance with the given script - local instance, errors = sandbox.new(script, self:filter(), self:scriptdir()) - if not instance then - os.raise("set_%s(): %s", name, errors) - end - - -- load the module - local module, errors = instance:module() - if not module then - os.raise("set_%s(): %s", name, errors) - end - - -- init the module - if module.init then - module.init() - end - - -- save module - scope[name] = module - end - - -- register implementation - self:_api_register_xxx_values(scope_kind, "set", implementation, ...) -end - -- register api for on_script function interpreter:api_register_on_script(scope_kind, ...) self:_api_register_xxx_script(scope_kind, "on", ...) diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua index 29e4d896e..72f1ad79a 100644 --- a/xmake/core/base/scopeinfo.lua +++ b/xmake/core/base/scopeinfo.lua @@ -65,7 +65,19 @@ end function _instance:_api_handle(values) local interp = self:interpreter() if interp then - values = interp:_handle(values, self._REMOVE_REPEAT, self._ENABLE_FILTER) + + -- remove repeat first for each slice with deleted item (__del_xxx) + if self._REMOVE_REPEAT and not table.is_dictionary(values) then + values = table.unique(values, function (v) return v:startswith("__del_") end) + end + + -- filter values + if self._ENABLE_FILTER then + values = interp:_filter(values) + end + + -- unwrap it if be only one + values = table.unwrap(values) end return values end @@ -215,6 +227,49 @@ function _instance:_api_add_keyvalues(name, key, ...) end end +-- set the api dictionary to the scope info +function _instance:_api_set_dictionary(name, dict_or_key, value) + + -- get the scope info + local scope = self._INFO + + -- check + if type(dict_or_key) == "table" then + local dict = {} + for k, v in pairs(dict_or_key) do + dict[k] = self:_api_handle(v) + end + scope[name] = dict + elseif type(dict_or_key) == "string" and value ~= nil then + scope[name] = {[dict_or_key] = self:_api_handle(value)} + else + -- error + os.raise("%s:set(%s, ...): invalid value type!", self:kind(), name, type(dict)) + end +end + +-- add the api dictionary to the scope info +function _instance:_api_add_dictionary(name, dict_or_key, value) + + -- get the scope info + local scope = self._INFO + + -- check + scope[name] = scope[name] or {} + if type(dict_or_key) == "table" then + local dict = {} + for k, v in pairs(dict_or_key) do + dict[k] = self:_api_handle(v) + end + table.join2(scope[name], dict) + elseif type(dict_or_key) == "string" and value ~= nil then + scope[name][dict_or_key] = self:_api_handle(value) + else + -- error + os.raise("%s:add(%s, ...): invalid value type!", self:kind(), name, type(dict)) + end +end + -- set the api pathes to the scope info function _instance:_api_set_pathes(name, ...) |
