lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Apr 19, 2011, at 11:58 AM, David Rio Deiros wrote:

> I was wondering if I could get some feedback on the following chunk of 
> lua code. 

How big is pl? 

Can you
(a) replace 'N' with '.' in the strings in pl
(b) turn your loop inside out and use gmatch [1] over read
?

Something like:

local function slide_over_read(read, pl)
   for patt, tbl in pairs(pl) do
      for w in read.gmatch(patt) do
         -- do something with the matched substring w and table tbl
      end
   end
end

[1] http://www.lua.org/manual/5.1/manual.html#pdf-string.gmatch

e