Module:SMART attributes: Difference between revisions
From Computing Classics Wiki
More width % tweaks |
No edit summary |
||
| Line 3: | Line 3: | ||
function p.makeSmartAttrTable() | function p.makeSmartAttrTable() | ||
-- Expensive function | -- Expensive function; incremenet the expensive count. | ||
mw.incrementExpensiveFunctionCount() | mw.incrementExpensiveFunctionCount() | ||
| Line 15: | Line 15: | ||
local hexConverter = require("Module:DecToHex") | local hexConverter = require("Module:DecToHex") | ||
-- Check numbers from 1 to 254, along with hex equivalent. | |||
for i=1, 254, 1 do | for i=1, 254, 1 do | ||
argName = "" | argName = "" | ||
| Line 27: | Line 28: | ||
end | end | ||
-- Draw table row if either the decimal or hexadecimal arg is populated. | |||
if (argName ~= "") then | if (argName ~= "") then | ||
table = table .. "|-" .. "\n" | table = table .. "|-" .. "\n" | ||
| Line 34: | Line 36: | ||
end | end | ||
-- Table closed | |||
table = table .. "|}" | table = table .. "|}" | ||
Revision as of 22:49, 29 January 2022
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: 90%;\" 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) then
argName = hexConverter.decToHex(i)
elseif (frame.args[i] ~= nil) then
argName = i
elseif (frame.args["0x" .. hexConverter.decToHex(i)] ~= nil) then
argName = "0x" .. hexConverter.decToHex(i)
elseif (frame.args["0x" .. string.upper(hexConverter.decToHex(i))] ~= nil) 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