Modul:Dv

Aus ARK: Survival Evolved Wiki
Wechseln zu: Navigation, Suche

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

local p = {}
function p.data( f )
  local args = f:getParent().args
  if args[1] == nil then
    return 'not enough parameters'
  end

  local path = args[1]

  -- for backwards compatibility
  if args[2] ~= nil then
    path = path .. '/' .. args[2]
  end

  path = path:gsub('[^%w/]', ''):lower()

  local folders = {}
  for part in string.gmatch(path..'/', "([^/]*)/") do
    table.insert(folders, part)
  end

  local aliases = mw.loadData('Module:dv/aliases')
  if aliases[folders[1]] ~= nil then
    folders[1] = aliases[folders[1]]
  end

  local data = mw.loadData('Module:dv/data')

  local node = data

  for _,f in ipairs(folders) do
    if node[f] ~= nil then
      node = node[f]
    else
      return '' -- no data available for given path
    end
  end

  if type(node) == 'table' then
    return 'parameter not specific enough' -- given path leads to a folder instead of a value
  else
    return node
  end
end
return p