Module:MOS modes: Difference between revisions

Ganaram inukshuk (talk | contribs)
No edit summary
Ganaram inukshuk (talk | contribs)
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
-- If it's nil, then return nil
function p.parse_mode_names(mode_names_unparsed)
function p.parse_mode_names(mode_names_unparsed)
if mode_names_unparsed == nil then
local mode_names = {}
return nil
for name in string.gmatch(mode_names_unparsed, '([^;]+)') do
else
local name_nospaces = name:gsub("%s+", "") -- Remove spaces
local mode_names = {}
table.insert(mode_names, name) -- Add to array
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
return mode_names
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 ~= nil then
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 ~= nil then
if #mode_names == number_of_modes then
result = result .. "|" .. mode_names[i] .. "\n"
result = result .. "|" .. mode_names[i] .. "\n"
end
end