调用方式
Functions.collections.compareArray(lhs, rhs)
将其记录为名为 Functions.collections.compareArray 的依赖项(接受自动补全即可完成),然后按该名称调用。
作用
遍历两个表中的条目,并使用 Lua 相等比较将每个值与另一个表中相应索引的值进行比较。普通的索引和相等元方法都会生效;嵌套内容不会被递归比较。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
lhs | table | 要比较的第一个表。 |
rhs | table | 要比较的第二个表。 |
返回值
| 1 | boolean | 当每个遍历到的条目双向比较都相等时为 true。 |
|---|
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
它不直接读取任何游戏 API。
示例
local wanted = { "Moonfire", "Sunfire" }
local applied = { "Moonfire", "Sunfire" }
return Functions.collections.compareArray(wanted, applied)源码
Functions/collections.lua,第 172 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Functions.collections.compareArray(lhs, rhs)
for k,v in pairs(lhs) do
if rhs[k] ~= v then
return false
end
end
for k,v in pairs(rhs) do
if lhs[k] ~= v then
return false
end
end
return true