diff options
| author | ruki <[email protected]> | 2022-03-02 23:29:35 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-03-02 23:29:35 +0800 |
| commit | f6a48a7481bffa3f8b97ac9cd509eb7f4c202559 (patch) | |
| tree | 77e3c441cb5d344e6037300a35ece91fa0c5f6a0 /xmake/core/base/table.lua | |
| parent | aeb97fe6d7d7385fddb494dc4f4a892993e03876 (diff) | |
add wraplock
Diffstat (limited to 'xmake/core/base/table.lua')
| -rw-r--r-- | xmake/core/base/table.lua | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 232f6962a..6c2b3aaf4 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -308,25 +308,35 @@ function table.to_array(iterator, state, var) return result, count end --- unwrap object if be only one -function table.unwrap(object) - if type(object) == "table" and not object.__object__ then - if #object == 1 then - return object[1] +-- unwrap array if be only one value +function table.unwrap(array) + if type(array) == "table" and not array.__wraplocked__ then + if #array == 1 then + return array[1] end end - return object + return array end --- wrap object to table -function table.wrap(object) - if nil == object then +-- wrap value to array +function table.wrap(value) + if nil == value then return {} end - if type(object) ~= "table" or object.__object__ then - return {object} + if type(value) ~= "table" or value.__wraplocked__ then + return {value} + end + return value +end + +-- lock table value to avoid unwrap +-- +-- a = {1}, wrap(a): {1}, unwrap(a): 1 +-- a = wraplock({1}), wrap(a): {a}, unwrap(a): a +function table.wraplock(value) + if type(value) == "table" then + value.__wraplocked__ = true end - return object end -- remove repeat from the given array |
