lua string concatenation in loop 字符串相加

lua 字符串相加不建议把字符串直接相连。如下面的代码会提示:lua string concatenation in loop

local buff = ""
for line in io.lines() do
    buff = buff .. line .. "\n"
end

应该像下面这样:

local t = {}
for line in io.lines() do
    table.insert(t, line)
end
s = table.concat(t, "\n") .. "\n"
Relative Articles