lua-users home
lua-l archive

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

On Sep 22, 2007, at 4:52 AM, Duck wrote:

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.

Very cool, I will try that! Thanks