Module:SMART attributes

From Australian Enthusiasts Wiki

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

-- Implements Template:SMART attributes.
local p = {}

function p.makeSmartAttrTable()
	-- Expensive function; incremenet the expensive count.
	mw.incrementExpensiveFunctionCount()
	
	frame = mw.getCurrentFrame():getParent()
	-- Start table
	table = ""
	table = table .. "{|cellspacing=\"0\" cellpadding=\"4\" border=\"1\" style=\"margin: 0 0 1em 1em; border: 1px #171717 solid; border-collapse: collapse; font-size: 100%;\" class=\"wikitable\"" .. "\n"
	table = table .. "!width=1%|'''ID'''" .. "\n"
	table = table .. "!width=17%|'''Name'''" .. "\n"
	
	local hexConverter = require("Module:DecToHex")
	
	-- Check numbers from 1 to 254, along with hex equivalent.
	for i=1, 254, 1 do
    	argName = ""
    	if (frame.args[hexConverter.decToHex(i)] ~= nil and frame.args[hexConverter.decToHex(i)] ~= "") then
    		argName = hexConverter.decToHex(i)
    	elseif (frame.args[i] ~= nil and frame.args[i] ~= "") then
			argName = i
    	elseif (frame.args["0x" .. hexConverter.decToHex(i)] ~= nil and frame.args["0x" .. hexConverter.decToHex(i)] ~= "") then
    		argName = "0x" .. hexConverter.decToHex(i)
    	elseif (frame.args["0x" .. string.upper(hexConverter.decToHex(i))] ~= nil and frame.args["0x" .. string.upper(hexConverter.decToHex(i))] ~= "") then
    		argName = "0x" .. string.upper(hexConverter.decToHex(i))
    	end
    	
    	-- Draw table row if either the decimal or hexadecimal arg is populated.
    	if (argName ~= "") then
    		table = table .. "|-" .. "\n"
    		table = table .. "|" .. "0x" .. string.upper(hexConverter.decToHex(i)) .. "/" .. tostring(i) .. "\n"
    		table = table .. "|" .. frame.args[argName] .. "\n"
    	end
 	end

	-- Table closed
	table = table .. "|}"
	
	return table
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.