Module:MOS modes: Difference between revisions
No edit summary |
No edit summary |
||
| Line 48: | Line 48: | ||
-- Helper function that parses mode names from a semicolon-delimited string and returns the names in an array | -- Helper function that parses mode names from a semicolon-delimited string and returns the names in an array | ||
function p.parse_mode_names(mode_names_unparsed) | function p.parse_mode_names(mode_names_unparsed) | ||
local mode_names = {} | |||
for name in string.gmatch(mode_names_unparsed, '([^;]+)') do | |||
local name_nospaces = name:gsub("%s+", "") -- Remove spaces | |||
table.insert(mode_names, name) -- Add to array | |||
end | end | ||
return mode_names | |||
end | end | ||
| Line 85: | Line 80: | ||
local mos_modes = p.modes_by_brightness(input_mos) | local mos_modes = p.modes_by_brightness(input_mos) | ||
local periods = rat.gcd(input_mos.nL, input_mos.ns) -- Needed for UDP | local periods = rat.gcd(input_mos.nL, input_mos.ns) -- Needed for UDP | ||
local number_of_modes = #mos_modes | |||
-- Make a table with a column for the mode (as a string of L's and s's) and UDP | -- Make a table with a column for the mode (as a string of L's and s's) and UDP | ||
| Line 94: | Line 90: | ||
-- If there are mode names (if the mode names array is not nil), then add a column for mode names | -- If there are mode names (if the mode names array is not nil), then add a column for mode names | ||
if mode_names | if #mode_names == number_of_modes then | ||
result = result .. "! Mode names\n" | result = result .. "! Mode names\n" | ||
end | end | ||
| Line 116: | Line 112: | ||
-- Add the mode's name, if given | -- Add the mode's name, if given | ||
if mode_names | if #mode_names == number_of_modes then | ||
result = result .. "|" .. mode_names[i] .. "\n" | result = result .. "|" .. mode_names[i] .. "\n" | ||
end | end | ||