Documentation for this module may be created at Module:Beast Signer Beasts/data/constructor/doc

-- <nowiki>
--------------------------------------------------------------------------------
-- Constructor for [[Module:Beast Signer Beasts/data]], pulled into its own
-- module for legibility purposes.
--
-- @TODO:
--    * Check for missing fields?
--    * Check for extra fields?
--    * Check for proper types?
--    * Generalize this, so I don't need to write a separate constructor for
--      every data module.
--------------------------------------------------------------------------------
local data = {}

local function constructor(newFields)
    local fields = {
        -- @TODO default values for optional fields
    }

    -- merge newFields into fields, replacing where necessary
    for k, v in pairs(newFields) do
        fields[k] = v
    end

    -- compound fields
    fields.link = fields.article == fields.name
        and ("[[" .. fields.article .. "]]")
        or ("[[" .. fields.article .. "|" .. fields.name .. "]]")

    -- make the fields available
    table.insert(data, fields)
    data[fields.name] = fields
end

-- @see <https://stackoverflow.com/a/9470669>
return function ()
    return data, constructor
end

-- </nowiki>
-- [[Category:Lua Modules]]
Community content is available under CC-BY-SA unless otherwise noted.