diff options
| author | ruki <[email protected]> | 2022-03-02 23:26:00 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-03-02 23:26:00 +0800 |
| commit | aeb97fe6d7d7385fddb494dc4f4a892993e03876 (patch) | |
| tree | 29d97c4b90fd0af6d841b7941bc22f288a7448b8 | |
| parent | cfdffbc896a2999c594caccfdaa323df16e3950b (diff) | |
fix wrap
| -rw-r--r-- | tests/modules/table/test.lua | 8 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 4 | ||||
| -rw-r--r-- | xmake/core/base/scopeinfo.lua | 4 | ||||
| -rw-r--r-- | xmake/core/base/table.lua | 8 |
4 files changed, 11 insertions, 13 deletions
diff --git a/tests/modules/table/test.lua b/tests/modules/table/test.lua index 156e619f9..5133e778f 100644 --- a/tests/modules/table/test.lua +++ b/tests/modules/table/test.lua @@ -16,9 +16,8 @@ function test_wrap(t) t:are_equal(table.wrap({}), {}) t:are_equal(table.wrap({1}), {1}) t:are_equal(table.wrap({{}}), {{}}) - local a = {1} - debug.setmetatable(a, {}) - t:are_equal(table.wrap(a), {a}) + local a = {1, __object__ = true} + t:are_equal(table.wrap({a}), {a}) end function test_unwrap(t) @@ -27,7 +26,6 @@ function test_unwrap(t) t:are_equal(table.unwrap({}), {}) t:are_equal(table.unwrap({1}), 1) t:are_equal(table.unwrap({{}}), {}) - local a = {1} - debug.setmetatable(a, {}) + local a = {1, __object__ = true} t:are_equal(table.unwrap(a), a) end diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index a226d3db2..50d7f3149 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -1066,7 +1066,7 @@ function interpreter:api_register_set_values(scope_kind, ...) if extra_config and extra_config.expand == false then for _, value in ipairs(values) do if type(value) == "table" then - setmetatable(value, {}) + value.__object__ = true end end else @@ -1118,7 +1118,7 @@ function interpreter:api_register_add_values(scope_kind, ...) if extra_config and extra_config.expand == false then for _, value in ipairs(values) do if type(value) == "table" then - setmetatable(value, {}) + value.__object__ = true end end else diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua index 02fb89299..4e0d5a73c 100644 --- a/xmake/core/base/scopeinfo.lua +++ b/xmake/core/base/scopeinfo.lua @@ -120,7 +120,7 @@ function _instance:_api_set_values(name, ...) if extra_config and extra_config.expand == false then for _, value in ipairs(values) do if type(value) == "table" then - setmetatable(value, {}) + value.__object__ = true end end else @@ -171,7 +171,7 @@ function _instance:_api_add_values(name, ...) if extra_config and extra_config.expand == false then for _, value in ipairs(values) do if type(value) == "table" then - setmetatable(value, {}) + value.__object__ = true end end else diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 73556c9fc..232f6962a 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -165,9 +165,9 @@ end -- copy the table to self function table.copy2(self, copied) - assert(type(copied) == "table") table.clear(self) - for k, v in pairs(copied) do + copied = copied or {} + for k, v in pairs(table.wrap(copied)) do self[k] = v end end @@ -310,7 +310,7 @@ end -- unwrap object if be only one function table.unwrap(object) - if type(object) == "table" and not getmetatable(object) then + if type(object) == "table" and not object.__object__ then if #object == 1 then return object[1] end @@ -323,7 +323,7 @@ function table.wrap(object) if nil == object then return {} end - if type(object) ~= "table" or getmetatable(object) then -- maybe object, we need wrap it too + if type(object) ~= "table" or object.__object__ then return {object} end return object |
