Content deleted Content added
Rewrite FEN converter to allow multi digit numbers |
OK, string.match isn’t flexible enough. We have to match only the head of the string, so we have to work with string.find() and string.sub() instead |
||
Line 133:
-- Loop over rows, which are delimited by /
for srow in string.gmatch("/" .. fen, "/%w+") do
srow = srow:gsub("/","")
srow = srow:gsub("%s*","")
print(srow) -- DEBUG
-- Loop over all letters and numbers in the row
-- Since Lua regexes do not have the | operator, we have
Line 138 ⟶ 141:
local index = 1
local piece = "" -- Piece can also be empty squares
local place = 0
local pstart = 0
local pend = 0
local length = srow:len()
while index < length do
-- If number not found, look for a letter (piece on board) local color = piece:match( '%u' ) and 'l' or 'd'
piece = piece:lower()
table.insert(res, piece .. color)
else
end
end
end
end
return res
end
function p.board(frame)
|