Module:Folger Shakespeare/sandbox

-- Modules we needlocal getArgs = require('Module:Arguments').getArgslocal warn = require('Module:Warning')-- Configurationlocal cfg = mw.loadData('Module:Folger Shakespeare/config');local _plays = mw.loadData('Module:Folger Shakespeare/plays');-- Turn plays table inside out so we can look up by alias toolocal plays = {}for _, play in pairs(_plays) dofor _, key in pairs(play.keys) doplays[key] = {["title"] = play.title,["folgerid"] = play.folgerid,["wikilink"] = play.wikilink}endend-- This module's function lookup table, used by the calling contextlocal p = {}function p.sfd(args)local play  = plays[args[1]]local act   = tonumber(args[2])local scene = tonumber(args[3])local line  = args[4]-- Check the play argumentif play == nil or play == "" thenwarn("No play argument provided, or the play provided was not recognised.")returnend-- Check the act argumentif act == nil or act == "" thenwarn("No act argument provided, or the act given was not numerical.")returnend-- Check the scene argumentif scene == nil or scene == "" thenwarn("No scene argument provided, or the scene given was not numerical.")returnend-- Check the line argumentif line == nil or line == "" thenwarn("No line argument provided.")returnendlocal display_line = lineif mw.ustring.match(line, '^%s*%d+[-–]%d+%s*$') thenline = mw.ustring.match(line, '^%s*(%d+)[-–]%d+%s*$')elseif mw.ustring.match(line, '^%s*%d+%s*$') thenline = mw.ustring.match(line, '^%s*(%d+)%s*$')elsewarn(("Could not coerce %s into a valid line specification."):format(line))returnendlocal location = mw.ustring.format('line-%d.%d.%d', act, scene, line)local url = mw.ustring.format(cfg.url_pattern, play.folgerid, act, scene, location)local   id = play.title .. act .. '_' .. scene .. '_' .. display_linelocal name = 'FOOTNOTE' .. idlocal location_link = mw.ustring.format(cfg.location_format, url, act, scene, display_line)local cite = mw.ustring.format("''%s'', %s", play.title, location_link)local result = mw.getCurrentFrame():extensionTag{name = 'ref',args = {name = name},content = cite,}return resultendfunction p.main(frame)local args = getArgs(frame)return p.sfd(args)endreturn p