Module:MOS: Difference between revisions

ArrowHead294 (talk | contribs)
mNo edit summary
Ganaram inukshuk (talk | contribs)
mNo edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- This module follows User:Ganaram inukshuk/Provisional style guide for Lua#Lua_style
-- This module follows [[User:Ganaram inukshuk/Provisional style guide for Lua]]
local et    = require("Module:ET")
local rat  = require("Module:Rational")
local utils = require("Module:Utils")


local rat = require("Module:Rational")
local utils = require("Module:Utils")
local et = require("Module:ET")
local p = {}
local p = {}
--------------------------------------------------------------------------------
------------------------------- HELPER FUNCTIONS -------------------------------
--------------------------------------------------------------------------------
-- Helper function
function p.find_item_in_table(table, item)
local item_found = false
for i = 1, #table do
if table[i] == item then
item_found = true
break
end
end
return item_found
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 40: Line 23:
-- If no equave "p/q" is provided, it's assumed to be 2/1-equivalent.
-- If no equave "p/q" is provided, it's assumed to be 2/1-equivalent.
function p.parse(unparsed)
function p.parse(unparsed)
local nL, ns, equave = unparsed:match("^(%d+)[Ll]%s*(%d+)[Ss]%s*(.*)$")
local nL, ns, equave = unparsed:match("^(%d+)[Ll].-(%d+)[Ss]%s*(.*)$")
nL = tonumber(nL)
nL = tonumber(nL)
ns = tonumber(ns)
ns = tonumber(ns)
Line 307: Line 290:
local current_mode = mode_string
local current_mode = mode_string
for i = 1, #mode_string do
for i = 1, #mode_string do
if not p.find_item_in_table(rotations, current_mode) then
if not utils.table_contains(rotations, current_mode) then
table.insert(rotations, current_mode)
table.insert(rotations, current_mode)
end
end