Module:LogicUtils: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 8: | Line 8: | ||
local nOutputs = tonumber(args[2]) | local nOutputs = tonumber(args[2]) | ||
for i= | for i=1,nInputs do | ||
html = html..string.format('"<th>Input %i</th>"', i) | html = html..string.format('"<th>Input %i</th>"', i) | ||
end | end | ||
for i= | for i=1,nOutputs do | ||
html = html..string.format('"<th>Output %i</th>"', i) | html = html..string.format('"<th>Output %i</th>"', i) | ||
end | end |
Revision as of 01:35, 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[1])
local nOutputs = tonumber(args[2])
for i=1,nInputs do
html = html..string.format('"<th>Input %i</th>"', i)
end
for i=1,nOutputs do
html = html..string.format('"<th>Output %i</th>"', i)
end
html = html.."</tr>"
local i = 3
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