lua-users home
lua-l archive

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


2018-02-14 12:04 GMT+02:00 steve donovan <steve.j.donovan@gmail.com>:

> Hisham and I were talking about the splitting-strings-into-tables and
> noticed that nearly every large Lua program re-implements this.

That merely goes to show that the problem does not have
a one-size-fits-all solution. Even small programs re-implement this.
E.g. I use a collector object, and usually don't even bother to find
an existing program that has one. I just type it in every time.

   do
local collect = {__index =
   function(tbl,x) rawset(tbl,#tbl+1,x) end
}
function collector()
  return setmetatable({},collect)
end
   end

words = collector()
("the quick brown fox jumps over the lazy dog"):gsub("%S+",words)


Sometimes the collector has added functionality, e.g. FIFO or
LIFO retrieval.

I don't expect everyone to like this way of doing it, but there's no way
I'm going to peruse docs just to find out if there is something
super-duper on the shelf.