Module:Chessboard mxn: Difference between revisions

Content deleted Content added
Fix Linter errors. I assume that this works; I am not a Lua programmer
Tag: Reverted
Slight logic simplification ("if a then else" to "if not a then")
 
(4 intermediate revisions by 4 users not shown)
Line 110:
if ( letters_bt ) then b = b .. letters_row(rev, numbers_lt, numbers_rt, cols) .. '\n' end
 
if not footer:match('^%s*$') then
then
else
caption = '<div class="thumbcaption">' .. footer .. '</div>\n'
end
b = '<table cellpadding=0 cellspacing=0 class="center noviewer" style="line-height: 0; background:white; font-size:88%; border:1px #c8ccd1 solid;'
.. 'padding:0; margin:auto">\n' .. b .. '\n</table>'
 
Line 122 ⟶ 120:
else
return '<div class="thumb ' .. align .. '">'
.. '{{<div class="center|">' .. header .. '}}</div>' .. '\n<div class="thumbinner" style="width:' .. width .. 'px;">\n'
.. b .. '\n' .. caption .. '</div></div>'
end
Line 133 ⟶ 131:
-- Loop over rows, which are delimited by /
for srow in string.gmatch("/" .. fen, "/%w+") do
srow = srow:gsub("/","") -- clean up row
-- Loop over all letters and numbers in the row
-- Since Lua regexes do not have the | operator, we have
for piece in srow:gmatch( "%w" ) do
-- to spell things if (piece:match("%d")) thenout
local index = -- if a digit1
local piece = "" -- Piece can also forbe k=1,pieceempty dosquares
local place = 0
local pstart = 0
local pend = 0
local length = srow:len()
while index <= length do
-- Look for a number. Can have multiple digits
pstart, pend = srow:find("%d+", index)
if pstart == index then
for piece in= srow:gmatchsub(pstart, "%w" pend) do
index = pend + 1
for k=1,tonumber(piece) do
table.insert(res,' ')
end
else
-- If number not found, look for a digitletter (piece on board)
local colorpstart = piecesrow:matchfind( '"%u' a",index) and 'l' or 'd'
pieceif pstart == index piece:lower()then
table.insert(res, piece ..= colorsrow:sub(pstart, pstart)
index = pstart + 1
-- l: White (light); d: Black (dark)
local color = piece:match( '%u' ) and 'l' or 'd'
piece = piece:lower()
table.insert(res, piece .. color)
else
index = length + 1 -- Break loop
end
end
end
end
 
return res
end