Module:GroupNameVariations: Difference between revisions
From Seven Sages of Rome
(Created page with "local p = "test" return p") |
No edit summary |
||
(26 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = " | -- Module:SMW | ||
local p = {} | |||
-- Return results | |||
function p.ask(frame) | |||
local queryResult = mw.smw.ask( string.format('[[Has Narrator::%s]][[Has Name Variation::+]]|?Has Name Variation', frame.args[1]) ) | |||
if queryResult == nil then | |||
return "(no values)" | |||
end | |||
if type( queryResult ) == "table" then | |||
local myResult = "" | |||
for num, row in pairs( queryResult ) do | |||
for property, data in pairs( row ) do | |||
local dataOutput = data | |||
if type( data ) == 'table' then | |||
dataOutput = mw.text.listToText( data, ', ', ' and ') | |||
end | |||
myResult = myResult .. dataOutput .. '\n' | |||
end | |||
end | |||
return myResult | |||
end | |||
end | |||
function groupMessages(array) | |||
local result = {}; | |||
for k, v in ipairs(array) do | |||
if not result[v.sender] then | |||
result[v.sender] = {}; | |||
end | |||
table.insert(result[v.sender], v); | |||
end | |||
return result; | |||
end | |||
return p | return p |
Latest revision as of 13:07, 4 June 2024
Documentation for this module may be created at Module:GroupNameVariations/doc
-- Module:SMW
local p = {}
-- Return results
function p.ask(frame)
local queryResult = mw.smw.ask( string.format('[[Has Narrator::%s]][[Has Name Variation::+]]|?Has Name Variation', frame.args[1]) )
if queryResult == nil then
return "(no values)"
end
if type( queryResult ) == "table" then
local myResult = ""
for num, row in pairs( queryResult ) do
for property, data in pairs( row ) do
local dataOutput = data
if type( data ) == 'table' then
dataOutput = mw.text.listToText( data, ', ', ' and ')
end
myResult = myResult .. dataOutput .. '\n'
end
end
return myResult
end
end
function groupMessages(array)
local result = {};
for k, v in ipairs(array) do
if not result[v.sender] then
result[v.sender] = {};
end
table.insert(result[v.sender], v);
end
return result;
end
return p