I need to modify the following function (found on http://lua-users.org...i/StringRecipes):
function wrap(str, limit) limit = limit or 72 local here = 1 -- the "".. is there because :gsub returns multiple values return ""..str:gsub("(%s+)()(%S+)()", function(sp, st, word, fi) if fi-here > limit then here = st return "\n"..word end end) end
Currently all the function does is it returns a string with words wrapped at a given margin. But what I'm trying to achieve is that every line is put into a table (ie lines with the words wrapped).
I have already tried the following but it doesn't work:
Lines = { } function wrap(str, limit) limit = limit or 72 local here = 1 return ""..str:gsub("(%s+)()(%S+)()", function(sp, st, word, fi) if fi-here > limit then here = st Lines[#Lines+1] = "\n"..word -- this does not work return "\n"..word end end) endDoing this gives the following result: http://repl.it/MDj
Any help/tips would be greatly appreciated.
Thanks.