Jump to: navigation, search

Module:CraftingDPL: Difference between revisions

No edit summary
No edit summary
 
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
function p.explode(delimiter, text)
  local list = {}; local pos = 1
  if string.find("", delimiter, 1) then
    -- We'll look at error handling later!
    error("delimiter matches empty string!")
  end
  while 1 do
    local first, last = string.find(text, delimiter, pos)
    if first then
      table.insert(list, string.sub(text, pos, first-1))
      pos = last+1
    else
      table.insert(list, string.sub(text, pos))
      break
    end
  end
  return list
end


function p.parseCats(frame)
function p.parseCats(frame)
     local s = tostring(frame.args[1])
     local s = tostring(frame.args[1])
     local arr = explode(";", s)
     local arr = p.explode(";", s)
     local s2 = ""
     local s2 = ""
    for k,v in pairs(arr) do s2 = s2.."[[Category:Recipe using "..v.."]] " end
    return s2
end


function explode(inputstr, sep)
    for i=1, #arr do
    if sep == nil then sep = "%s" end
        if (arr[i] ~= nil and arr[i] ~= "") then
    local t={}
                s2 = s2 .. "[[Category:Recipe using " .. arr[i] .."]] "
    local i=1
        for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
                t[i] = str
                i = i + 1
         end
         end
        return t
    end
 
    --return s2
    return "" --Needs efficiency improvements
end
end


return p
return p

Latest revision as of 20:36, 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.explode(delimiter, text)
  local list = {}; local pos = 1
  if string.find("", delimiter, 1) then
    -- We'll look at error handling later!
    error("delimiter matches empty string!")
  end
  while 1 do
    local first, last = string.find(text, delimiter, pos)
    if first then
      table.insert(list, string.sub(text, pos, first-1))
      pos = last+1
    else
      table.insert(list, string.sub(text, pos))
      break
    end
  end
  return list
end

function p.parseCats(frame)
    local s = tostring(frame.args[1])
    local arr = p.explode(";", s)
    local s2 = ""

    for i=1, #arr do
        if (arr[i] ~= nil and arr[i] ~= "") then
                s2 = s2 .. "[[Category:Recipe using " .. arr[i] .."]] "  
        end
    end

    --return s2
    return "" --Needs efficiency improvements
end

return p


Cookies help us deliver our services. By using our services, you agree to our use of cookies.