Call as
Functions.text.wrap(str, limit)
Record it as a dependency named Functions.text.wrap (accepting the completion does this), then call it by that name.
Also accepted under the former namespace utils.
What it does
Wrap text at whitespace boundaries near a target column count. Long words are retained intact.
Arguments
| Name | Type | What it does |
|---|---|---|
str | string | Text to wrap. |
limit | number | nil | Target line width, default 72 characters. |
Returns
| 1 | string | Text with line breaks inserted at word boundaries. |
|---|
Editions
Built In helpers are registered on every edition. What differs is the game API they read; where one is missing the helper falls back or returns nil with a reason.
It reads no game API directly.
Example
local note = Functions.text.wrap("Use defensive cooldowns before the tank swap", 20)
local _, breaks = note:gsub("\n", "")
return breaks >= 1Source
Functions/text.lua, line 37. Read only in game; Duplicate makes an editable copy.
Functions.text.wrap(str, limit)
limit = limit or 72
local here = 1
-- the "".. is there because :gsub returns multiple values
return ""..str:gsub("(%s+)()(%S+)()",
function(_, st, word, fi)
if fi-here > limit then
here = st
return "\n"..word
end
end)