lua-users home
lua-l archive

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

I need to iterate four times because the subs need to be
applied in a certain order:
"Note, there is no guarantee as to the  order in which keys
will be stored in a table when using dictionaries so the order of retrieval of keys using pairs() is not guaranteed."

You can make what amounts to an "ordered dictionary" by making your substitution table both an array and a dictionary, something like this:

 subs = {
   1 = ">~h|",
   2 = "<~h|",
   3 = ">~w|",
   23 = "<p",

   ">~h|" = GREEK_SMALL_LETTER_ETA_WITH_PSILI_AND_[...snip...]

Then you can write something like this:

 local function mysubs(lines)
    for _,v in ipairs(subs) do
      lines = string.gsub(lines,v,subs[v]);
    return lines;

This works because ipairs() does bring out the "array-style" entries (i.e. those with index 1..n) in a table in numeric order.