參考資料 › 函式參考 › Functions

Functions.text.wrap

公用

呼叫方式

Functions.text.wrap(str, limit)

將它記錄為名為 Functions.text.wrap 的相依項目(接受自動完成即可完成此步驟),然後以該名稱呼叫。

也接受舊命名空間 utils 下的名稱。

作用

在接近目標欄數的空白邊界處對文字換行。長單字會保持完整。

參數

名稱類型作用
strstring要換行的文字。
limitnumber | nil目標行寬,預設為 72 個字元。

傳回值

1string在單字邊界處插入換行的文字。

版本

內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。

它不會直接讀取任何遊戲 API。

範例

local note = Functions.text.wrap("Use defensive cooldowns before the tank swap", 20)
local _, breaks = note:gsub("\n", "")
return breaks >= 1

原始碼

Functions/text.lua,第 37 行。在遊戲中為唯讀;「複製」會產生一份可編輯的複本。

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)

返回函式參考