We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
目前想要判断一个列表中是否含有某元素,在script scope只需要
local var = import("core.base.hashset").of(mytable):has(myelement)
但在description scope需要
local var = false for _, v in ipairs(mytable) do if v == element then var = true break end end
相当麻烦。lua本身也没有提供一种这样的机制,见 https://stackoverflow.com/questions/2282444/how-to-check-if-a-table-contains-an-element-in-lua 。对比之下,cmake只需要一行
set(VAR (myelement IN_LIST mytable))
这个操作还是挺常见的,既然lua没有提供,xmake能否提供一个简单通用的api来判断列表对元素的包含关系?
table.contain(mytable, myelement) -- return true / false
或者
mytable:has(myelement)
让hashset在description scope也能用
The text was updated successfully, but these errors were encountered:
加了个 table.contains(t, v)
table.contains(t, v)
Sorry, something went wrong.
改进了下 table.contains(t, 1, 2, 3, ...) 包含其中一个就返回 true
table.contains(t, 1, 2, 3, ...)
这样的接口感觉不如table.contains(t, {1, 2, 3, ...})实用,后者还能表达两个table的包含关系。不过应该也是等价的,现在可以写
table.contains(t, {1, 2, 3, ...})
table.contains(t, unpack(subset))
但写起来不省事,也跟 is_plat has_config 这种风格不一致,并且还会每次new 一个额外的table
No branches or pull requests
你在什么场景下需要该功能?
目前想要判断一个列表中是否含有某元素,在script scope只需要
但在description scope需要
相当麻烦。lua本身也没有提供一种这样的机制,见 https://stackoverflow.com/questions/2282444/how-to-check-if-a-table-contains-an-element-in-lua 。对比之下,cmake只需要一行
这个操作还是挺常见的,既然lua没有提供,xmake能否提供一个简单通用的api来判断列表对元素的包含关系?
描述可能的解决方案
或者
描述你认为的候选方案
让hashset在description scope也能用
The text was updated successfully, but these errors were encountered: