Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将1个或多个列表[string][string]添加到LUA中的新列表中_Lua - Fatal编程技术网

将1个或多个列表[string][string]添加到LUA中的新列表中

将1个或多个列表[string][string]添加到LUA中的新列表中,lua,Lua,我有很多大的列表,格式如下 listA = {} listA['Suburb Name A']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff} listA['Suburb Name B']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff} listA['Suburb Name C']['Street Name'

我有很多大的列表,格式如下

listA = {}
   listA['Suburb Name A']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
   listA['Suburb Name B']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
   listA['Suburb Name C']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
   listA['Suburb Name D']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
   excreta... .. . 


listB = {}
   listB['Suburb Name E']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
   listB['Suburb Name F']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
   listB['Suburb Name G']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
   listB['Suburb Name H']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
   excreta... .. . 
我想做的是把这些列表复制到一个新的列表中,一个新的列表,它是两个列表的组合

像这样的

ListNew = {}
ListNew = Add(listA, ListNew )
ListNew = Add(listB, ListNew )
ListNew = Add(listC, ListNew )
有什么想法吗


(编辑以删除我的错误代码,并尝试通过只输入所需的基本信息使问题更清楚。)

找到了解决方案!感谢所有试图帮助的人

function add(target, source)
    for i in pairs(source) do
        if target[i] == nil then
            target[i] = {}
        end
        for j in pairs(source[i]) do
            target[i][j] = source[i][j]
        end
    end
end

-- used like this
newList = {}
add(newList, listA)
add(newList, listB)
add(newList, listC)

您不需要解释编辑;编辑答案或问题时有一个特殊的文本框:)我认为编写问题和答案比编写
add
函数花费更多的时间。