Quick line counting function to compute the approximate number of lines required to show a string in an input box.
The second parameter which is the maximum number of lines is optional and will default to 9 if not passed.
Requires: None
Code
-
function linecount(string,maxlines) --[[ @function linecount @description Works out approximate number of lines to display a text string in an input box. @parms string: string to process mandatory maxlines: maximum height for text box, defaults to 9 lines if not provided ]] maxlines = maxlines or 9 local intLines = 1 for strLine in string.gmatch(string.."\n","(.-)\n") do intLines = intLines + math.ceil(string.len(strLine)/100) end return math.min(intLines,maxlines) end