将table.insert与动态变量名一起使用

时间:2017-01-14 01:38:31

标签: lua lua-table dynamic-variables

我有一个关于如何在Lua中使用table.insert函数使用动态变量名的问题。

我想用动态变量名创建一些表,然后使用table.insert函数访问这些表以填充值,但是,我不清楚如何访问table.insert函数中新创建的表。

到目前为止我的代码看起来像这样:

local attributeNames = {"attribute1","attribute2","attribute3"}
local attributes = {}

for k, v in pairs(attributeNames) do
        // If attribute name equals name of type then create a new table with 
           that type name
        if(string.match(v, type)) then
          attributes[v] = {}
          currentAttribute = v
          break
        end
      end
// Insert values into the table with that type name, here I do not get how to call 
   the table of name "attribute1" for example to fill it with values
table.insert (attributes[currentAttribute], values)

非常欢迎任何帮助! :)

0 个答案:

没有答案
相关问题