-- a, b are the last 2 words pairs = {} text = {} ntext = 0 word = {} wordIdx = {} function p(m, s) if s ~= nil then for i = 1, s:len() do local c = s:sub(i, i) ntext = ntext+1 text[ntext] = c if c >= "a" and c <= "z" or c >= "A" and c <= "Z" then nword = nword+1 word[nword] = c else if nword ~= 0 then newWord(table.concat(word)) word = {} nword = 0 end end end end local x = wordIdx[b] if x ~= nil then return table.concat(text, "", x, math.min(ntext, x+math.min(100, m)-1)) end end function newWord(w) a = b b = w wordIdx[b] = ntext+1 end