Module:LogicUtils: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
local args = args or frame:getParent().args | local args = args or frame:getParent().args | ||
local html = "<table class=\"wikitable\"><tr>" | local html = "<table class=\"wikitable\"><tr>" | ||
local nInputs = tonumber(args[ | local nInputs = tonumber(args["inputs"]) | ||
local nOutputs = tonumber(args[ | local nOutputs = tonumber(args["outputs"]) | ||
for i=1,nInputs do | for i=1,nInputs do | ||
Line 26: | Line 24: | ||
html = html.."</tr>" | html = html.."</tr>" | ||
local i = | if args.caption ~= nil then | ||
html = html.."<caption>"..args.caption.."</caption>" | |||
end | |||
local i = 1 | |||
while args[i] ~= nil do | while args[i] ~= nil do | ||
mw.log(args[i]) | mw.log(args[i]) |
Revision as of 01:41, 7 September 2025
Documentation for this module may be created at Module:LogicUtils/doc
local p = {}
p.truth_table = function(frame, args)
local args = args or frame:getParent().args
local html = "<table class=\"wikitable\"><tr>"
local nInputs = tonumber(args["inputs"])
local nOutputs = tonumber(args["outputs"])
for i=1,nInputs do
html = html.."<th>Input"
if nInputs > 1 then
html = html..string.format(" %i", i)
end
html = html.."</th>"
end
for i=1,nOutputs do
html = html.."<th>Output"
if nOutputs > 1 then
html = html..string.format(" %i", i)
end
html = html.."</th>"
end
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