Module:DynBox

From Discord Dungeons Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:DynBox/doc

local p = {}
local infobox = require('Module:Infobox')

function tableLength(T)
	local count = 0
	for _ in pairs(T) do count = count + 1 end
	return count
end

function p.dynBox(frame)
	local args = {
		decat = "yes",
		child = "yes",
		title = frame.args[tableLength(frame.args)]
	}

	local i = 1

	local oldVar = ""

	for name, value in pairs(frame.args) do

		if(string.len(oldVar) <= 0) then
			oldVar = value
		end
		if(tonumber(name) % 2 == 0) then
			args["label"..i] = frame.args[tonumber(name)-1]
			args["data"..i] = value
			oldVar = ""
		end

		i = i+1
	end

	return infobox.infobox(args)
end

return p