lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Niklas Frykholm wrote:
[...]
function string:rep(n)
   local out = ""
   for i=1,n do out = out .. self end
   return out
end

Did you know that there already is a string:rep() method?

Also, if you're doing this sort of thing a lot, you should take a look at table:concat(). Concatenating strings like you're doing here is extremely slow. This kind of code is considerably faster:

  local out = {}
  for i = 1, n do out[i] = self end
  return table.concat(out, " ")

--
David Given
dg@cowlark.com