Jump to content

Module:LogicUtils: Difference between revisions

From Logic World Wiki
Created page with "local p = {} p.truth_table = function(frame, args) local args = args or frame:getParent().args local html = "<table class=\"wikitable\"><tr>" for token in string.gmatch(args[1], "[^%s]+") do html = html.."<th>"..token.."</th>" end html = html.."</tr>" for i=2,#args do html = html.."<tr>" for token in string.gmatch(args[i], "[^%s]+") do if token == "0" then html = html.."<td style=\"color: red\">0</td>" elseif token == "1" then html = html.."..."
 
No edit summary
Line 14: Line 14:
for token in string.gmatch(args[i], "[^%s]+") do
for token in string.gmatch(args[i], "[^%s]+") do
if token == "0" then
if token == "0" then
html = html.."<td style=\"color: red\">0</td>"
html = html.."<td style=\"color:red; font-weight:bold\">0</td>"
elseif token == "1" then
elseif token == "1" then
html = html.."<td style=\"color: green\">1</td>"
html = html.."<td style=\"color:green; font-weight:bold\">1</td>"
else
else
html = html.."<td>"..token.."</td>"
html = html.."<td>"..token.."</td>"

Revision as of 01:18, 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>"

	for token in string.gmatch(args[1], "[^%s]+") do
		html = html.."<th>"..token.."</th>"
	end
	html = html.."</tr>"
	
	for i=2,#args do
		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>"
	end

	html = html.."</table>"
	return html
end

return p