More actions
dustloop>TarkusLee Created page with "local p = {} local mArguments local cargo local cache = {} --- Return the Moves data and cache the data for reuse on the same page --- --- @return table local function getGlossaryData( gameSpecifier ) -- Return cached data if #cache > 0 then return cache end -- Lazy initalize Module:Cargo cargo = require( 'Module:Cargo' ) local tables = 'Glossary' local fields = 'term,definition,gameSpecifier' local args = { where = string.format..." |
dustloop>TarkusLee No edit summary |
||
| Line 35: | Line 35: | ||
return cache | return cache | ||
end | |||
local function getTerm( term, gameSpecifier ) | |||
local data = getGlossaryData( gameSpecifier ) | |||
local terms = {} | |||
for _, key in pairs( inputs ) do | |||
local match = data[ key ] | |||
if not match then | |||
error( string.format( 'Could not find matching term: %s', term ) ) | |||
end | |||
terms[ key ] = data[ term ] | |||
end | |||
return terms | |||
end | end | ||
| Line 49: | Line 64: | ||
local term = args['term'] | local term = args['term'] | ||
local term = args['gameSpecifier'] | |||
if not term then | if not term then | ||
Revision as of 14:55, 19 May 2024
Documentation for this module may be created at Module:Keyword/doc
local p = {}
local mArguments
local cargo
local cache = {}
--- Return the Moves data and cache the data for reuse on the same page
---
--- @return table
local function getGlossaryData( gameSpecifier )
-- Return cached data
if #cache > 0 then return cache end
-- Lazy initalize Module:Cargo
cargo = require( 'Module:Cargo' )
local tables = 'Glossary'
local fields = 'term,definition,gameSpecifier'
local args = {
where = string.format('MoveData_GGACR.chara="%s"', chara),
orderBy = 'MoveData_GGACR._rowID',
limit = "101",
}
local results = cargo.getQueryResults( tables, fields, args, false )
local items = {}
for _, result in pairs( results ) do
items[result.input] = result
end
-- Save to cache
cache = items
-- mw.logObject(cache)
return cache
end
local function getTerm( term, gameSpecifier )
local data = getGlossaryData( gameSpecifier )
local terms = {}
for _, key in pairs( inputs ) do
local match = data[ key ]
if not match then
error( string.format( 'Could not find matching term: %s', term ) )
end
terms[ key ] = data[ term ]
end
return terms
end
function p.main(frame)
mArguments = require( 'Module:Arguments' )
local args = mArguments.getArgs(frame)
return p._main(args)
end
--- Return the wikitext needed for the template
---
--- @return string
function p._main( args )
local term = args['term']
local term = args['gameSpecifier']
if not term then
error( 'No term specified for the template' )
end
local html
return tostring(html)
end
return p