Concatenation of tables in Lua

后端 未结 9 792
难免孤独
难免孤独 2020-12-09 15:04

ORIGINAL POST

Given that there is no built in function in Lua, I am in search of a function that allows me to append tables together. I have google

9条回答
  •  攒了一身酷
    2020-12-09 15:18

    And one more way:

    for _,v in ipairs(t2) do 
        table.insert(t1, v)
    end
    

    It seems to me the most readable one - it iterates over the 2nd table and appends its values to the 1st one, end of story. Curious how it fares in speed to the explicit indexing [] above

提交回复
热议问题