Lua - convert a table into a comma separated list

clua7 picture clua7 · Jul 6, 2011 · Viewed 9.9k times · Source

I need to convert a table into a comma separated list in order to save it to a text file. Is there a built in method for doing this in Lua?

Answer

lhf picture lhf · Jul 6, 2011

If your table is an array, you can use table.concat to print CSVs:

t={10,20,30}
print(table.concat(t,","))

outputs 10,20,30.