Module:LogicUtils: Difference between revisions
Appearance
No edit summary |
No edit summary Tag: Reverted |
||
Line 10: | Line 10: | ||
else | else | ||
-- str is a number | -- str is a number | ||
mw.log(mw.dumpObject(count)) | |||
mw.log(mw.dumpObject(kind)) | |||
if count == 1 then | if count == 1 then | ||
names[1] = kind | names[1] = kind |
Revision as of 01:56, 7 September 2025
Documentation for this module may be created at Module:LogicUtils/doc
local p = {}
function parse_io(kind, html, str)
local count = tonumber(str)
local names = {}
if count == nil then
-- str is a list of IO names
names = mw.text.split(str, ",")
else
-- str is a number
mw.log(mw.dumpObject(count))
mw.log(mw.dumpObject(kind))
if count == 1 then
names[1] = kind
else
for i=1,count do
names[i] = string.format("%s %i", kind, i)
end
end
end
for i, v in ipairs(names) do
html = html.."<th> "..v.."</th>"
end
return html
end
p.truth_table = function(frame, args)
local args = args or frame:getParent().args
local html = "<table class=\"wikitable\"><tr>"
html = parse_io("Input", html, args.inputs)
html = parse_io("Output", html, args.outputs)
html = html.."</tr>"
if args.caption ~= nil then
html = html.."<caption>"..args.caption.."</caption>"
end
local i = 1
while args[i] ~= nil do
mw.log(args[i])
html = html.."<tr>"
for token in string.gmatch(args[i], "[^%s]+") do
if token == "0" then
html = html.."<td style=\"color:red; font-weight:bold\">0</td>"
elseif token == "1" then
html = html.."<td style=\"color:green; font-weight:bold\">1</td>"
else
html = html.."<td>"..token.."</td>"
end
end
html = html.."</tr>"
i = i + 1
end
html = html.."</table>"
return html
end
return p