FANDOM


local HFX = {}
local HF   = require("Module:HF")
 
function HFX.parseFields( args ) 
  local input = {}
        input.fields   = {}   -- Actual data
        input.vars     = {}   -- "Global" variables
 
  -- Distribute args to vars and fields.
  local indexes = {} -- Table used to sort indexes of fields
  local fields = {}  -- Temporary fields table
  local f = 0        -- Fields consecutive indice
 
  for k, v in pairs(args) do
    local keySplit = HF.explode( ":", tostring(k) )
    local index  = tonumber( HF.trim( keySplit[1] ) )
    local key    = tostring( HF.trim( keySplit[2] ) )
    local value  = tostring( HF.trim( v )           )
    if index > 0 then
      if fields[index] == nil then
        table.insert( indexes, index )
        fields[index] = {}
      end
      fields[index][key] = value
    else
      if not HF.isempty( HF.trim( value ) ) then input.vars[key] = value end
    end
  end
 
  table.sort( indexes )
  for i, index in ipairs(indexes) do
    f = f + 1
    input.fields[f] = {}
    input.fields[f] = fields[index]
  end
  return input
end
 
return HFX

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.