tl;dr: I’m trying to figure out if I can use string.gmatch to return the start location of words.
ie, this example from the Lua manual:
s = "hello world from Lua. "
for w in string.gmatch(s, "%a+") do
print(w)
end
…Each word is returned. Presumably there is a way to also return the start value as you would get using string.find(), but I can’t seem to find anything on returning that value using the control codes (eg: “%a+” in that example)
Details : I’m trying to build a function who’s job is only to look through a string, and if it exceeds a given length, insert a line break. But it has to be smart enough to insert the linebreak before or after a word, not inbetween.
display.newText() does do text wrapping, but it’s simply looking at the width of the object at the time, so in my case (typing out words letter by letter), the autowrap function would simply go midway through a word, realize the next character would take it too far, and then teleport the word to the bottom. I’m trying to write something that looks through the string ahead of time and removes that possibility by inserting \n line breaks.
local limit = 25 -- max number of characters per line
if wordstart + wordlength \> limit then
--insert linebreak at wordstart
end
Something like that, only with an iterator so I can add 2nd and 3rd linebreaks as necessary… [import]uid: 41884 topic_id: 29743 reply_id: 329743[/import]