检索表名称

时间:2014-10-27 12:14:26

标签: lua key-value lua-table

有没有办法检索表的名称?例如,从这张表中我只想提取键名称" Mimic"," Molibdeno"," Tamarindo"," Wrenna"

UnitScanDB = {
    profiles = {
        Mimic = {
        ...
        },
        Molibdeno = {
        ...
        },
        Tamanrindo = {
        ...
        },
        Wrenna = {
        ...
        }
    }
}

2 个答案:

答案 0 :(得分:3)

您可以iterate使用pairs

覆盖内部表格{{3}}
for k in pairs(UnitScanDB.profiles) do
   -- handle k
end

使用上述循环,您可以将所有键复制到新表中:

local names = {}
for k in pairs(UnitScanDB.profiles) do
  table.insert(names, k)
end

答案 1 :(得分:0)

您只需按名称访问这些键即可:

mimic = UnitScanDB.profiles.Mimic
molibdeno = UnitScanDB.profiles.Molibdeno