Module:Species: Difference between revisions
From Portals of Phereon Wiki
Content added Content deleted
(Creating table for species module. Expect a lot of changes and I test/debug stuff) |
No edit summary |
||
(14 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
if (v ~= nil) then |
if (v ~= nil) then |
||
if fv == 'name' then |
if fv == 'name' then |
||
temp_item[#temp_item+1] = ' |
temp_item[#temp_item+1] = 'id="' .. v .. '" |[[' .. v .. ']]'; |
||
elseif fv == 'text' then |
elseif fv == 'text' then |
||
temp_item[#temp_item+1] = v; |
temp_item[#temp_item+1] = v; |
||
elseif fv == 'num' then |
elseif fv == 'num' then |
||
if string.find(v, '-') ~= nil then |
|||
temp_item[#temp_item+1] = ' ' .. v; |
|||
else |
|||
temp_item[#temp_item+1] = v; |
|||
end |
|||
elseif fv == 'linklist' then |
|||
for match in (v..'/'):gmatch("(.-)/") do |
|||
if match ~= 'Nothing' then |
|||
temp_item[#temp_item+1] = '[[' .. match .. ']] '; |
|||
end |
|||
end |
|||
else |
|||
temp_item[#temp_item+1] = v; |
temp_item[#temp_item+1] = v; |
||
end |
end |
Latest revision as of 22:55, 10 April 2022
Documentation for this module may be created at Module:Species/doc
local p = {};
local cargo = mw.ext.cargo;
local utils = require( "Module:Utils" );
function p.species(frame)
local temp_res = {};
local fstr = utils.toNumberedTable(frame.args[2]);
local results = cargo.query(frame.args[1], utils.trimBrackets(frame.args[3]), utils.toTable(utils.trimBrackets(frame.args[4])));
for _, result in ipairs(results) do
local temp_item = {'|-\n'};
for r, fv in ipairs( fstr ) do
local v = result["'" .. tostring(r) .. "'"];
temp_item[#temp_item+1] = '|';
if (v ~= nil) then
if fv == 'name' then
temp_item[#temp_item+1] = 'id="' .. v .. '" |[[' .. v .. ']]';
elseif fv == 'text' then
temp_item[#temp_item+1] = v;
elseif fv == 'num' then
if string.find(v, '-') ~= nil then
temp_item[#temp_item+1] = ' ' .. v;
else
temp_item[#temp_item+1] = v;
end
elseif fv == 'linklist' then
for match in (v..'/'):gmatch("(.-)/") do
if match ~= 'Nothing' then
temp_item[#temp_item+1] = '[[' .. match .. ']] ';
end
end
else
temp_item[#temp_item+1] = v;
end
end
temp_item[#temp_item+1] = '\n';
end
temp_res[#temp_res+1] = table.concat(temp_item,"");
end
local restbl = table.concat(temp_res,"");
return restbl;
end
return p