Modul:Utils: Unterschied zwischen den Versionen

Aus Eco - Deutsches Wiki
Wechseln zu:Navigation, Suche
[unmarkierte Version][unmarkierte Version]
(Die Seite wurde neu angelegt: „local p = {} -- Trims and parses the args into a table, then returns the table function p.normaliseArgs(frame) local origArgs = frame:getParent().args loc…“)
 
Keine Bearbeitungszusammenfassung
Zeile 5: Zeile 5:
   local origArgs = frame:getParent().args
   local origArgs = frame:getParent().args
   local args = {}
   local args = {}
 
 
   for k, v in pairs(origArgs) do
   for k, v in pairs(origArgs) do
     v = mw.text.trim(tostring(v))
     v = mw.text.trim(tostring(v))
Zeile 12: Zeile 12:
     end
     end
   end
   end
 
  return args
end
function p.checkImage(name, too_expensive)
  local icon = name:gsub('%s+', '') .. '_Icon.png'
  if too_expensive then
    return icon
  end
  if mw.title.makeTitle('File', icon).file.exists then
    return icon
  else
    return 'NoImage.png'
  end
end


   return args
-- mw.LoadData prevents #table from working correctly
function p.tableLen(tbl)
   local count = 0
    for _, v in ipairs(tbl) do
      if v == nil then
        return count
      end
      count = count + 1
    end
  return count
end
end


return p
return p

Version vom 5. März 2021, 02:55 Uhr

Die Dokumentation für dieses Modul kann unter Modul:Utils/Doku erstellt werden

local p = {}

-- Trims and parses the args into a table, then returns the table
function p.normaliseArgs(frame)
  local origArgs = frame:getParent().args
  local args = {}
  
  for k, v in pairs(origArgs) do
    v = mw.text.trim(tostring(v))
    if v ~= '' then
      args[k] = v
    end
  end
  
  return args
end

function p.checkImage(name, too_expensive)
  local icon = name:gsub('%s+', '') .. '_Icon.png'
  if too_expensive then
    return icon
  end

  if mw.title.makeTitle('File', icon).file.exists then
    return icon
  else
    return 'NoImage.png'
  end
end

-- mw.LoadData prevents #table from working correctly
function p.tableLen(tbl)
  local count = 0
    for _, v in ipairs(tbl) do
      if v == nil then
        return count
      end
      count = count + 1
    end
  return count
end

return p