-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenumerate.lua
More file actions
32 lines (25 loc) · 728 Bytes
/
Copy pathenumerate.lua
File metadata and controls
32 lines (25 loc) · 728 Bytes
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
local enumerators = {}
return function(enums, existing_enumerator)
if type(enums) ~= 'string' or enums:len() == 0 then return end
local words = enums:upper():gsub('\n', ' '):Split(' ')
local first_valid_word = nil
local enumerator = 1
if existing_enumerator then
enumerator = enumerators[existing_enumerator] or 1
end
for _, word in ipairs(words) do
if word ~= '' and word ~= ' ' then
if not first_valid_word then
first_valid_word = word
end
_G[word] = enumerator
enumerator = enumerator + 1
end
end
if enumerator > 0 then
local idx = first_valid_word:match('^([%w0-9]+)')
if not idx then return end
enumerators[idx] = enumerator - 1
end
return enumerator - 1
end