-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoreLibs.lua
More file actions
46 lines (36 loc) · 1.11 KB
/
MoreLibs.lua
File metadata and controls
46 lines (36 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function getSecondToLastItem(tbl)
local keys = {}
-- Collect all the keys from the table
for key in pairs(tbl) do
table.insert(keys, key)
end
-- Sort the keys
table.sort(keys)
-- Check if there are at least two elements
if #keys < 2 then
return nil, "Not enough elements in the table"
end
-- Get the second to last key
local secondToLastKey = keys[#keys - 1]
-- Return the value associated with this key
return tbl[secondToLastKey]
end
-- Function to wrap text into lines that fit within width W
function wrapText(words, maxWidth)
local lines = {}
local currentLine = ""
for _, word in ipairs(words) do
local testLine = currentLine .. (currentLine == "" and "" or " ") .. word
local testWidth, _ = draw.GetTextSize(testLine)
if testWidth > maxWidth then
table.insert(lines, currentLine)
currentLine = word
else
currentLine = testLine
end
end
if currentLine ~= "" then
table.insert(lines, currentLine)
end
return lines
end