Module:CraftingDPL: Difference between revisions
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
function p.parseCats(frame) | function p.parseCats(frame) | ||
local s = tostring(frame.args[1]) | local s = tostring(frame.args[1]) | ||
return | local arr = explode(";", s) | ||
local s2 = "" | |||
for k,v in pairs(arr) do s2 = s2+"[[Category:Recipe using "+v+"]] " end | |||
return s2 | |||
end | |||
function explode(div, str) | |||
if (div=='') then return false end | |||
local pos = 0 | |||
local arr = {} | |||
for st,sp in function() return string.find(str,div,pos,true) end do | |||
table.insert(arr,string.sub(str,pos,st-1)) | |||
pos = sp+1 | |||
end | |||
table.insert(arr,string.sub(str,pos)) | |||
return arr | |||
end | end | ||
return p | return p |
Revision as of 18:59, 13 February 2014
Returns a list of categories based on the string of items that are used for crafting. Used in the creation of DPL categories for crafting templates.
local p = {}
function p.parseCats(frame)
local s = tostring(frame.args[1])
local arr = explode(";", s)
local s2 = ""
for k,v in pairs(arr) do s2 = s2+"[[Category:Recipe using "+v+"]] " end
return s2
end
function explode(div, str)
if (div=='') then return false end
local pos = 0
local arr = {}
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1))
pos = sp+1
end
table.insert(arr,string.sub(str,pos))
return arr
end
return p